Rolling back objects to a previous state?

In my order process code I start a mySql transaction and start doing inserts and assigning insert ids to the relevant objects in php. When I encounter certain sql errors I rollback the sql transaction, but obviously any ids set in my php objects are still set. Any suggestions for a good way to go back to a previous state? Clone all your affected objects at the start of the process? Is there a better way?

Well why not? If you want something more sophisticated, you might have a look at state managing libraries such as php_redux (disclaimer: I only know the JS original and this one seems to be a one-man “fun” port, but you’ll get an idea).

If you just want to abstract away the storing of the objects’ properties, maybe something like this would do the trick?

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.