note 81569 added to language.oop5.static

From: Date: Tue, 04 Mar 2008 12:41:11 +0000
Subject: note 81569 added to language.oop5.static
Groups: php.notes 
Request: Send a blank email to php-notes+get-136729@lists.php.net to get a copy of this message
There is a problem to make static property shared only for objects of self class not defining it in every child class. Example: class a { public static $s; public function get() { return self::$s; } } class b extends a { } class c extends b { } a::$s = 'a'; $c = new c(); echo $c->get(); // a There is solution i found: class a { public final function v($vs = null) { static $s = null; if(!is_null($vs)) $s = $vs; return $s; } } class b extends a { } class c extends b { } $a = new a(); $a->v('a'); $aa = new a(); $aa->v('last a'); $c = new c(); $c->v('c'); echo $a->v().' - '.$c->v(); // last a - c ---- Server IP: 195.54.192.44 Probable Submitter: 85.235.219.115 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.static.php Edit -- https://master.php.net/note/edit/81569 Del: integrated -- https://master.php.net/note/delete/81569/integrated Del: useless -- https://master.php.net/note/delete/81569/useless Del: bad code -- https://master.php.net/note/delete/81569/bad+code Del: spam -- https://master.php.net/note/delete/81569/spam Del: non-english -- https://master.php.net/note/delete/81569/non-english Del: in docs -- https://master.php.net/note/delete/81569/in+docs Del: other reasons-- https://master.php.net/note/delete/81569 Reject -- https://master.php.net/note/reject/81569 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#136729) next »