note 15917 added to language.oop
| From: | foobardotcom at poczta dot onet dot pl | Date: | Mon, 08 Oct 2001 18:52:17 +0000 |
| Subject: | note 15917 added to language.oop | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-18694@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.
--
http://www.php.net/manual/en/language.oop.php
http://master.php.net/manage/user-notes.php?action=edit+15917
http://master.php.net/manage/user-notes.php?action=delete+15917
http://master.php.net/manage/user-notes.php?action=reject+15917