PHP5 : __sleep() and __wakeup()
| From: | Frédéric Hardy | Date: | Thu, 12 Aug 2004 15:11:46 +0000 |
| Subject: | PHP5 : __sleep() and __wakeup() | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-193583@lists.php.net to get a copy of this message | ||
Hello !
I have a problem with __sleep() and __wakeup() with php 5.0.0.
if you have a class like that :
class foo
{
private $var = 'var';
function __construct()
{
...
}
function __sleep()
{
return array('var');
}
function wakeup()
{
}
}
and php code like this :
$myFoo = new foo();
var_dump(serialize($myFoo));
the 'var' property was not serialized because it is protected !!!
However, if you do not defined __sleep() method, 'var' is serialized !!!
Conclusion : the programmer can not define properties wich must be serialized, but the language can serialized all properties, even if they are private or protected !!!
And if the prgrammer (me) want not to put in session all properties, it is impossible !!!
Any solutions ?
Best regards,
Fred