note 81572 added to language.oop5.static

From: Date: Tue, 04 Mar 2008 13:25:53 +0000
Subject: note 81572 added to language.oop5.static
Groups: php.notes 
Request: Send a blank email to php-notes+get-136732@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.117 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.static.php Edit -- https://master.php.net/note/edit/81572 Del: integrated -- https://master.php.net/note/delete/81572/integrated Del: useless -- https://master.php.net/note/delete/81572/useless Del: bad code -- https://master.php.net/note/delete/81572/bad+code Del: spam -- https://master.php.net/note/delete/81572/spam Del: non-english -- https://master.php.net/note/delete/81572/non-english Del: in docs -- https://master.php.net/note/delete/81572/in+docs Del: other reasons-- https://master.php.net/note/delete/81572 Reject -- https://master.php.net/note/reject/81572 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#136732) next »