note 14388 added to keyword.paamayim_nekudotayim.php
| From: | () | Date: | Sun, 29 Jul 2001 08:10:24 +0000 |
| Subject: | note 14388 added to keyword.paamayim_nekudotayim.php | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-16016@lists.php.net to get a copy of this message | ||
That's how to make class' static variable in PHP4. That means reference returned by
function value() is the same for all instances of class O, thus they can share common data. This
reference is common just for instances on same PHP page, of course.
<? class O {
function &value() {
static $val=0;
return $val;
}
}
$o1= &new O;
$o2= &new O;
echo "\$o1: ".$o1->value()."<b"."r>";
echo "\$o2: ".$o2->value()."<b"."r>";
$ref1= &$o1->value();
$ref1= 5;
$ref2= &$o2->value();
$ref2= 10;
echo "\$o1: ".$o1->value()."<b"."r>";
echo "\$o2: ".$o2->value()."<b"."r>";
?>
http://www.php.net/manual/en/keyword.paamayim_nekudotayim.php