note 30288 added to language.variables.scope
| From: | ben-xo at rack1 dot php dot net | Date: | Thu, 13 Mar 2003 04:05:31 +0000 |
| Subject: | note 30288 added to language.variables.scope | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-45199@lists.php.net to get a copy of this message | ||
regarding the above "unset" example: I quote from the manual page for "unset".
"If a static variable is unset() inside of a function, unset() destroyes the variable and all
its references. "
As mentioned above, on this page, static vars are implemented as references. When you unset() a
reference, what you are doing is deleting a particular name for that variable. In your example, you
delete the LOCAL NAME $a, but the static contents are still there (hidden) and next time you call
your function, a NEW LOCAL NAME (again $a...) is linked to the SAME backing data.
Workaround would be something like "$a = null".
unset($a) is very much like $a = &null however, which, if you read the notes above, won't
have the desired affect on static or global variables.
--
http://www.php.net/manual/en/language.variables.scope.php
http://master.php.net/manage/user-notes.php?action=edit+30288
http://master.php.net/manage/user-notes.php?action=delete+30288
http://master.php.net/manage/user-notes.php?action=reject+30288