Use of PHP Magic Methods __sleep and __wakeup
问题 What is the use of the __sleep and __wakeup magic methods in PHP? I read the PHP documentation but it's still not clear: class sleepWakeup { public function __construct() { // constructor // } public function __sleep() { echo 'Time to sleep.'; } public function __wakeup() { echo 'Time to wakeup.'; } } $ob = new sleepWakeup(); // call __sleep method echo $ob->__sleep(); echo "\n"; // call __wakeup method echo $ob->__wakeup(); This sample code prints: Time to sleep. Time to wakeup. If I were to