note 81569 deleted from language.oop5.static by felipe

From: Date: Mon, 24 Mar 2008 23:13:44 +0000
Subject: note 81569 deleted from language.oop5.static by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-137518@lists.php.net to get a copy of this message
Note Submitter: Siarhei ---- 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

« previous php.notes (#137518) next »