|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2000-09-20 18:02 UTC] stas@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 21:00:01 2025 UTC |
The following code acts weird in respect to unsetting the variable. I'm trying to clarify unset in the PHP docs and I've come across this inconsistancy. Something similar to this was mentioned in bug report 2015, but I think this might be different. function foo() { static $a; $a++; echo "$a\n"; // let's unset it once it hits 3 if ($a == 3) { echo "unsetting #$a\n"; unset($a); } echo "value of a: $a\n"; } for ($i = 0; $i < 10; $i++) { foo(); } This generates the following output: 1 value of a: 1 2 value of a: 2 3 unsetting #3 value of a: 4 value of a: 4 5 value of a: 5 6 value of a: 6 7 value of a: 7 8 value of a: 8 9 value of a: 9 10 value of a: 10 When the static variable is unset, it's only unset inside the function. Instead of $a starting over at 1, it retains it's original value through each function call. Not sure if this is intended, but it's very strange behavior.