Re: PHP5 : __sleep() and __wakeup()
| From: | Frédéric Hardy | Date: | Thu, 12 Aug 2004 16:33:26 +0000 |
| Subject: | Re: PHP5 : __sleep() and __wakeup() | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-193599@lists.php.net to get a copy of this message | ||
I'am using php 5.0.0 release.
Try this :
var_dump($test);
var_dump(unserialize(serialize($test)));
You should obtain something like that for fist var_dump :
object test
string test -> 'var'
and for the second var_dump :
object test
string test -> 'var'
string test -> & null
Best regards
Fred
PS : I can not test my code in 'live', because I have currently no php5 available (it is on my laptop, and i can not use it at work).
So, perhaps that my example is wrong :-(.
but in some case, i'am sure that __sleep() and __wakeup does not work correctly !!
Curt Zirzow wrote:
* Thus wrote Frdric Hardy:-- =================================================================== Frederic HARDY Email: fch@hexanet.fr HEXANET SARL URL: http://www.hexanet.fr/ ZAC Les Charmilles Tel: +33 (0)3 26 79 30 05 3, allée Thierry Sabine Direct: +33 (0)3 26 61 77 84 BP 202 - 51686 REIMS CEDEX 2 FRANCE ===================================================================class foo { private $var = 'var'; ... function __sleep() {what version are you running? this works perfectly fine: string(26) "O:3:"foo":1:{s:3:"var";N;}" Curtreturn array('var');} } 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 !!!