Re: Unsetting global variables within a function?
| From: | Paul DuBois | Date: | Thu, 01 Jun 2000 16:39:44 +0000 |
| Subject: | Re: Unsetting global variables within a function? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-843@lists.php.net to get a copy of this message | ||
At 11:18 AM -0500 2000-06-01, Paul DuBois wrote:
I have an HTML form. One of the form actions requires that I clear out all the current form variables so that I can present a new, empty form. I want to unset these variables from within a function. Suppose I have a variable named $date from the form. This does not appear to work: function xxx () { global $date; unset ($date); } On the other hand, this does work: function xxx () { unset ($GLOBALS["date"]); } Just curious why this is.Well, naturally, just *minutes* after posting this message, I ran across another discussion on the developer's list that explains exactly why this is. That discussion contained a pointer to this article, which has the details: http://www.zend.com/zend/art/ref-count.php Basically, variables declared with global are references to the "real" global, and unsetting them only unsets the local reference. -- Paul DuBois, paul@snake.net