Re: _sleep and _wakeup
- From: "AlexVN" <alexander.netkachev@xxxxxxxxx>
- Date: 17 Jun 2006 16:01:28 -0700
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/
.
- Follow-Ups:
- Re: _sleep and _wakeup
- From: Water Cooler v2
- Re: _sleep and _wakeup
- References:
- _sleep and _wakeup
- From: Water Cooler v2
- _sleep and _wakeup
- Prev by Date: _sleep and _wakeup
- Next by Date: Re: IDE for PHP
- Previous by thread: _sleep and _wakeup
- Next by thread: Re: _sleep and _wakeup
- Index(es):
Relevant Pages
|