note 45282 deleted from language.variables.scope by crell
| From: | crell@php.net | Date: | Thu, 31 Mar 2022 19:38:13 +0000 |
| Subject: | note 45282 deleted from language.variables.scope by crell | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-217929@lists.php.net to get a copy of this message | ||
Note Submitter: info AT SyPlex DOT net
----
Some times you need to access the same static in more than one function. There is an easy way to
solve this problem:
<?php
// We need a way to get a reference of our static
function &getStatic() {
static $staticVar;
return $staticVar;
}
// Now we can access the static in any method by using it's reference
function fooCount() {
$ref2static = & getStatic();
echo $ref2static++;
}
fooCount(); // 0
fooCount(); // 1
fooCount(); // 2
?>