note 73345 added to language.oop.magic-functions
| From: | phreak at aon dot at | Date: | Sun, 18 Feb 2007 22:38:19 +0000 |
| Subject: | note 73345 added to language.oop.magic-functions | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-123561@lists.php.net to get a copy of this message | ||
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.
----
Server IP: 194.153.94.10
Probable Submitter: 85.124.121.233
----
Manual Page -- http://www.php.net/manual/en/language.oop.magic-functions.php
Edit -- https://master.php.net/note/edit/73345
Del: integrated -- https://master.php.net/note/delete/73345/integrated
Del: useless -- https://master.php.net/note/delete/73345/useless
Del: bad code -- https://master.php.net/note/delete/73345/bad+code
Del: spam -- https://master.php.net/note/delete/73345/spam
Del: non-english -- https://master.php.net/note/delete/73345/non-english
Del: in docs -- https://master.php.net/note/delete/73345/in+docs
Del: other reasons-- https://master.php.net/note/delete/73345
Reject -- https://master.php.net/note/reject/73345
Search -- https://master.php.net/manage/user-notes.php