note 73345 deleted from language.oop.magic-functions by danbrown
| From: | danbrown@php.net | Date: | Sat, 07 Nov 2009 18:54:54 +0000 |
| Subject: | note 73345 deleted from language.oop.magic-functions by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-162503@lists.php.net to get a copy of this message | ||
Note Submitter: phreak at aon dot at
----
I just noticed the following:
if you use $this inside __sleep, it does not change the original instance, because its a copy. very
naughty.
the only workaround for this reference - copy problem with __sleep i found is to use global
variables, which is not very beautiful.
<?php
class A {
var $e;
function __sleep() {
$this->e = 'sleeping...';
return array('e');
}
}
$a = new A();
$a->e = 'MyValue';
echo serialize($a)."\n";
echo $a->e; // echoes "MyValue" - not "sleeping..."
?>
interesting to note:
<?php
echo serialize(&$a); // does what is expected
?>
BUT: thats deprecated.