note 21711 added to function.unset
| From: | "admin\\" at /networkessence dot net | Date: | Thu, 23 May 2002 23:40:03 +0000 |
| Subject: | note 21711 added to function.unset | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-30961@lists.php.net to get a copy of this message | ||
If a static variable is unset() inside of a function, unset() destroyes the variable and all its
references.
This statement is clearly false given the following example:
function foo() {
static $a;
$a++;
echo "$a\n";
unset($a);
}
foo();
foo();
foo();
The above example would output:
1
2
3
If $a was being destroyed, then it would not increment (bug I guess). BUT
unset does work properly outside of functions
Example:
static $a;
$a++;
echo $a;
unset($a);
$a++;
echo $a;
unset($a);
would output:
1
1
which is correct. I would assume this is a bug considering the output of the first example
contradicts the manual.
--
http://www.php.net/manual/en/function.unset.php
http://master.php.net/manage/user-notes.php?action=edit+21711
http://master.php.net/manage/user-notes.php?action=delete+21711
http://master.php.net/manage/user-notes.php?action=reject+21711