note 109639 added to language.oop5.late-static-bindings

From: Date: Fri, 03 Aug 2012 17:03:11 +0000
Subject: note 109639 added to language.oop5.late-static-bindings
Groups: php.notes 
Request: Send a blank email to php-notes+get-189912@lists.php.net to get a copy of this message
For static properties declared in parent class and not redeclared in sub-classes, static:: in parent class would hit parent's properies. (class a and b below) If those were declared in sub-classes, static:: in parent class will hit sub-classes's own. (class c and d below). e.g. <?php $_CONFIG['a'] = '1'; $_CONFIG['b'] = '2'; $_CONFIG['c'] = '3'; $_CONFIG['d'] = '4'; class static_base { static protected $config; static protected $module_name = ''; static public function load() { global $_CONFIG; static::$config = $_CONFIG[static::$module_name]; } static public function dump() { var_dump(static::$config); } } class a extends static_base { static protected $module_name = 'a'; } class b extends static_base { static protected $module_name = 'b'; } class c extends static_base { static protected $module_name = 'c'; static protected $config; } class d extends static_base { static protected $module_name = 'd'; static protected $config; } a::load(); b::load(); a::dump(); // 2 b::dump(); // 2 c::load(); d::load(); c::dump(); // 3 d::dump(); // 4 ---- Server IP: 69.147.83.197 Probable Submitter: 115.171.163.96 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.late-static-bindings.php Edit -- https://master.php.net/note/edit/109639 Del: integrated -- https://master.php.net/note/delete/109639/integrated Del: useless -- https://master.php.net/note/delete/109639/useless Del: bad code -- https://master.php.net/note/delete/109639/bad+code Del: spam -- https://master.php.net/note/delete/109639/spam Del: non-english -- https://master.php.net/note/delete/109639/non-english Del: in docs -- https://master.php.net/note/delete/109639/in+docs Del: other reasons-- https://master.php.net/note/delete/109639 Reject -- https://master.php.net/note/reject/109639 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#189912) next »