note 45282 added to language.variables.scope
| From: | infoATSyPlexDOTnet at osu1 dot php dot net | Date: | Wed, 01 Sep 2004 00:35:03 +0000 |
| Subject: | note 45282 added to language.variables.scope | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-75811@lists.php.net to get a copy of this message | ||
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
?>
----
Manual Page -- http://www.php.net/manual/en/language.variables.scope.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+45282
Delete -- http://master.php.net/manage/user-notes.php?action=delete+45282&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+45282&report=yes
Search -- http://master.php.net/manage/user-notes.php