Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我知道有serialize()/unserialize()来存储具有魔术 __sleep 和 __wakeup 方法的对象。但我有一个项目,其中存储对象$_SESSION没有任何问题。
$_SESSION
现在我想知道什么时候需要使用序列化?
是为了交叉引用吗?
当您将对象放入内部时, PHP 在内部使用serialize/等价物,因此只要您遵守规则(不要尝试序列化资源,为反序列化提供类定义),它就会自动运行,正如您已经看到的那样。unserialize$_SESSION
serialize
unserialize
仅当您打算使用某些自定义机制保留值时,您才需要显式使用serialize/ 。unserialize