note 111662 added to language.variables.scope
| From: | Anonymous | Date: | Wed, 13 Mar 2013 17:55:11 +0000 |
| Subject: | note 111662 added to language.variables.scope | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-194061@lists.php.net to get a copy of this message | ||
I had code not too unlike this:
<?php
function foo() {
static $s = 0;
if ($s == 0) {
echo 'setting $s to "foo"<br>';
$s = "foo";
}
}
// a little test
foo();
foo();
foo();
?>
Which prints 'setting $s to "foo"' three times.
The code needs to be:
<?php
function foo() {
static $s = '';
if ($s == '') {
echo 'setting $s to "foo"<br>';
$s = "foo";
}
}
?>
----
Server IP: 69.147.83.199
Probable Submitter: 24.60.223.242
----
Manual Page -- http://php.net/manual/en/language.variables.scope.php
Edit -- https://master.php.net/note/edit/111662
Del: integrated -- https://master.php.net/note/delete/111662/integrated
Del: useless -- https://master.php.net/note/delete/111662/useless
Del: bad code -- https://master.php.net/note/delete/111662/bad+code
Del: spam -- https://master.php.net/note/delete/111662/spam
Del: non-english -- https://master.php.net/note/delete/111662/non-english
Del: in docs -- https://master.php.net/note/delete/111662/in+docs
Del: other reasons-- https://master.php.net/note/delete/111662
Reject -- https://master.php.net/note/reject/111662
Search -- https://master.php.net/manage/user-notes.php