note 15917 deleted from language.oop by jimw

From: Date: Mon, 08 Oct 2001 19:16:49 +0000
Subject: note 15917 deleted from language.oop by jimw
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-18698@lists.php.net to get a copy of this message
I've just invented new amazing feature in PHP - 'static' fields. It is of course wrapped with a method, because there's no static fields of classes in this language. Here's an short example: class Foo { function &myField() { static $myField; return $myField; } function setMyField($val) { $tmp =& Foo::myField(); $tmp = $val; } } Foo::setMyField("first value"); echo "first value of myField is: " . Foo::myField() . "<br>\n"; Foo::setMyField("second value"); echo "second value of myField is: " . Foo::myField() . "<br>\n"; As you see, everything is wrapped using method returning an reference. I put there accessor method (setMyField) to explain, how to modify value of this static variable -- using references. That's a pity, that PHP developers forgot about static fields for classes, but this example shows an easy workaround.

« previous php.notes (#18698) next »