Posted by AlexVN on 12/18/88 11:50
Water Cooler v2 wrote:
> I didn't understand from this
>
> http://in2.php.net/manual/en/language.oop.magic-functions.php
>
> whether we, the programmer, have to implement _sleep and _wakeup (like
> .NET's IDisposable.Dispose()) or it is done by PHP internally on a
> class that uses resources?
Hi,
__sleep and __wakeup are the methods, that you can implement in your
class. They are just like events that occur before serialization and
after unserialization. Consider this:
class MyClass {
function __sleep() {
echo "__sleep\n";
return array();
}
function __wakeup() {
echo "__wakeup\n";
}
}
$c = new MyClass();
echo "Sleep: ";
$str = serialize($c);
echo "Wakeup: ";
$c1 = unserialize($str);
The output will be:
Sleep: __sleep
Wakeup: __wakeup
Sincerely,
Alexander
http://www.alexatnet.com/
[Back to original message]
|