note 14388 deleted from keyword.paamayim-nekudotayim by sobak
| From: | sobak@php.net | Date: | Fri, 25 Nov 2016 06:28:47 +0000 |
| Subject: | note 14388 deleted from keyword.paamayim-nekudotayim by sobak | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-207652@lists.php.net to get a copy of this message | ||
Note Submitter: peter at textstore dot c() dot il
----
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>";
?>