I am trying to create a serialize/unserialize library in userland, based on a binary format (AMF).
The problem is that I have to reconstruct certain objects, and to retain state I have to bypass the constructor and check if there is a __wakeup method instead (like unserialize does)

There doesnt seem to be a way to do this, I tried it with casting, but :

(myClass)$object obviously wont work.. I also looked into __set_state, which is what var_export forces to use for any class, but its also not quite what im looking for, because i want a transparerent system like PHP's unserialize().

To eloborate in my problem, I put this online:


To summarize my question: How can i mimic PHP's unserialize behaviour regarding 'sleeping' classes.

Any help would be greatly appriciated!