note 87404 added to language.oop5.magic
| From: | jsnell at e-normous dot com | Date: | Wed, 03 Dec 2008 22:01:49 +0000 |
| Subject: | note 87404 added to language.oop5.magic | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-147602@lists.php.net to get a copy of this message | ||
Be very careful to define __set_state() in classes which inherit from a parent using it, as the
static __set_state() call will be called for any children. If you are not careful, you will end up
with an object of the wrong type. Here is an example:
class A
{
public $var1;
public static function __set_state($an_array)
{
$obj = new A;
$obj->var1 = $an_array['var1'];
return $obj;
}
}
class B extends A {
}
$b = new B;
$b->var1 = 5;
eval('$new_b = ' . var_export($b, true) . ';');
var_dump($new_b);
/*
object(A)#2 (1) {
["var1"]=>
int(5)
}
*/
----
Server IP: 209.41.74.194
Probable Submitter: 67.165.183.32
----
Manual Page -- http://www.php.net/manual/en/language.oop5.magic.php
Edit -- https://master.php.net/note/edit/87404
Del: integrated -- https://master.php.net/note/delete/87404/integrated
Del: useless -- https://master.php.net/note/delete/87404/useless
Del: bad code -- https://master.php.net/note/delete/87404/bad+code
Del: spam -- https://master.php.net/note/delete/87404/spam
Del: non-english -- https://master.php.net/note/delete/87404/non-english
Del: in docs -- https://master.php.net/note/delete/87404/in+docs
Del: other reasons-- https://master.php.net/note/delete/87404
Reject -- https://master.php.net/note/reject/87404
Search -- https://master.php.net/manage/user-notes.php