note 112193 added to language.oop5.magic
| From: | staff at pro-unreal dot de | Date: | Thu, 16 May 2013 06:08:52 +0000 |
| Subject: | note 112193 added to language.oop5.magic | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-194816@lists.php.net to get a copy of this message | ||
To avoid instanciating the parent instead of the inherited class for __set_state() as reported by
jsnell, you could use late static binding introduced in PHP 5.3:
<?php
class A {
public static function __set_state($data) {
return new static();
}
}
class B extends A {
}
$instance = new B();
eval('$test = ' . var_export($instance, true) . ';');
var_dump($test);
// -> object(B)#2 (0) {
// }
?>
----
Server IP: 69.147.83.199
Probable Submitter: 178.4.193.5
----
Manual Page -- http://php.net/manual/en/language.oop5.magic.php
Edit -- https://master.php.net/note/edit/112193
Del: integrated -- https://master.php.net/note/delete/112193/integrated
Del: useless -- https://master.php.net/note/delete/112193/useless
Del: bad code -- https://master.php.net/note/delete/112193/bad+code
Del: spam -- https://master.php.net/note/delete/112193/spam
Del: non-english -- https://master.php.net/note/delete/112193/non-english
Del: in docs -- https://master.php.net/note/delete/112193/in+docs
Del: other reasons-- https://master.php.net/note/delete/112193
Reject -- https://master.php.net/note/reject/112193
Search -- https://master.php.net/manage/user-notes.php