The PDO contains a state that cannot be represented in serialization format. For example, a PDO contains an open connection to a database server.
If you try to deserialize a serialized PDO, the __wakeup() method will need to reconnect to the database server. This will require that the authentication credentials be stored in a readable form in a serialized PDO, which is a no-no security.
I have been working on the Zend Framework component Zend_Db for a long time, and I specially designed the Zend_Db_Adapter object so that for this reason it would not be serializable. Instances of Zend_Db_Table, Zend_Db_Table_Row, etc. They can be serializable, but they cannot be βliveβ after deserialization, until you assign a newly connected instance of Zend_Db_Adapter to it.
In addition, there is no guarantee that the database server will be available at the time of deserialization of the PDO. It is unclear whether this means that deserialization will be considered "unsuccessful."
The same serialization restrictions apply to other resources, such as sockets or file descriptors.
See also Why not every type of serializable object?
Bill karwin
source share