The production server for my current employer is still running PHP 4.x; for some set of reasons, upgrading PHP versions is out of the question.
I’m implementing a web app which heavily relies upon usage of OOP. I’ve found that I’m able to emulate a good amount of PHP 5 OOP features through little hacks or clever workarounds (generally located in a template base class from which I extend all other classes). Presently, I’m in need of the __sleep() and __wakeup() magic methods for my classes; is there a way to emulate this functionality in PHP 4.x without wrapping calls to serialize() and unserialize() with method calls?
You could probably accomplish this by renaming and then overriding the built-in
serialize()andunserialize()functions usingrename_function()andoverride_function(). It’s definitely a bit of a hack, though.Edit: Oops, I just realized that those are debugger methods, so this probably won’t work for you. Runkit provides the same functionality, but it is an extension which needs to be installed, and I assume you won’t be able to do that either if you can’t upgrade PHP.
Edit 2: In either case, for the sake of clarity and maintainability, I think you’re better off just defining your own serialization and deserialization functions wherein you introspect the target object, call special functions if available, and then call
serialize().