note 90178 added to language.oop5.magic

From: Date: Thu, 09 Apr 2009 07:46:25 +0000
Subject: note 90178 added to language.oop5.magic
Groups: php.notes 
Request: Send a blank email to php-notes+get-152988@lists.php.net to get a copy of this message
[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! ---- Server IP: 91.199.167.18 Probable Submitter: 217.195.249.69 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.magic.php Edit -- https://master.php.net/note/edit/90178 Del: integrated -- https://master.php.net/note/delete/90178/integrated Del: useless -- https://master.php.net/note/delete/90178/useless Del: bad code -- https://master.php.net/note/delete/90178/bad+code Del: spam -- https://master.php.net/note/delete/90178/spam Del: non-english -- https://master.php.net/note/delete/90178/non-english Del: in docs -- https://master.php.net/note/delete/90178/in+docs Del: other reasons-- https://master.php.net/note/delete/90178 Reject -- https://master.php.net/note/reject/90178 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#152988) next »