The memento design pattern allows us to get the state of a given object in a way that enables us to set it back either in the same original object or in another one.
You can find the source code available for free download in my ‘PHP Design Patterns’ course, which is available for free personal usage at www.abelski.com.