Bug #13967 Updated: unset() on a static variable causes it to forget it is static
| From: | jeroen@php.net | Date: | Wed, 07 Nov 2001 23:29:43 +0000 |
| Subject: | Bug #13967 Updated: unset() on a static variable causes it to forget it is static | ||
| References: | 1 | Groups: | php.dev php.doc |
| Request: | Send a blank email to php-dev+get-69777@lists.php.net to get a copy of this message | ||
ID: 13967
Updated by: jeroen
Reported By: david@php.net
Status: Open
Old Bug Type: Scripting Engine problem
Bug Type: Documentation problem
Operating System: Debian Linux
PHP Version: 4.0.6
New Comment:
Like with global, static is a keyword linking a variable specially. unset() will completely destroy
the variable with all links it might have. This is expected behaviour, or at least a known
side-effect. With the current way of handling variables internally, this is not going to change.
This isn't stressen enough in the manual, so changing to documentation problem.
Previous Comments:
------------------------------------------------------------------------
[2001-11-06 21:49:10] david@php.net
Doing unset() on a static variable causes it to forget the fact that it is static for the rest of
the function.
e.g.
<?
function abc() {
static $a = 123;
echo "On entry, a = $a\n";
unset($a);
$a = 456;
}
abc();
abc();
?>
should give 123 then 456. It gives 123 and 123.
Replacing unset($a) with $a = null, or removing the unset() entirely has the desired result of
giving 123 then 456.
------------------------------------------------------------------------
Edit this bug report at http://bugs.php.net/?id=13967&edit=1