note 90178 deleted from language.oop5.magic by thiago
| From: | thiago@php.net | Date: | Thu, 09 Apr 2009 12:15:25 +0000 |
| Subject: | note 90178 deleted from language.oop5.magic by thiago | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-153012@lists.php.net to get a copy of this message | ||
Note Submitter: rudie-de-hotblocks
----
[jsnell at e-normous dot com] makes a very good points a few posts earlier.
Fortunately from PHP 5.3 on, there will be Late Static Bindings
(www.php.net/oop5.late-static-bindings) which enable you to call the class that was actually called
(instead of 'A' or 'self'). Like this:
<?php
class A
{
public $var1;
public static function __set_state($an_array)
{
$class = get_called_class();
$obj = new $class;
$obj->var1 = $an_array['var1'];
return $obj;
}
}
class B extends A {}
?>
Even though B::__set_state() still inherits from class A, it now initiates the correct class using
the new function get_called_class().
Excellent work PHP team!