I know there is serialize()/unserialize() to store objects with magic __sleep and __wakeup methods. But I have a project where objects are stored in $_SESSION without any problems.
Now I am wondering when I need to use serialize?
Is it for cross references?
PHP internally uses the equivalent of
serialize/unserializewhen you put objects inside$_SESSION, so as long as you obey the rules (don’t try to serialize resources, provide class definitions for unserializing) it all works automatically as you have already seen.You would need to explicitly use
serialize/unserializeonly if you intend to persist values using some custom mechanism.