Re: [PHP4BETA] unset and global behavior problems.
| From: | Zeev Suraski | Date: | Fri, 19 May 2000 17:30:39 +0000 |
| Subject: | Re: [PHP4BETA] unset and global behavior problems. | ||
| References: | 1 | Groups: | php.version4 |
| Request: | Send a blank email to php-version4+get-15262@lists.php.net to get a copy of this message | ||
This is a known difference; The definition for unset() in PHP 4.0, and
its behavior, are much more consistent than that of PHP 3.0, and it is a
bit different when it comes to global variables. unset() deletes a symbol
from the symbol table, or in other words, erases a given variable. In PHP
4.0, when you define 'global $var;', you essentially ask for the local
$var to point to the global $var (they're reference to each other).
unset()ing the local $var symbol will not affect the global $var.
To unset() a global in PHP 4.0, use unset($GLOBALS["varname"]).
Zeev
On Fri, 19 May 2000, Andrew A. Neuschwander wrote:
>
> While working with the sourceforge php code, I can across this behavioral
> difference between php 3 and 4. I wanted to know if this is an intended
> change or not. The following script does very different things in the two
> versions.
>
> <?php
> function thing() {
> global $var;
> unset($var);
> $var = "Simpson";
> }
> $var = "Homer";
> echo "$var<br>";
> thing();
> echo "$var<br>";
> ?>
>
> In php3 the output is :
>
> Homer
> Simpson
>
> In php4 the output is :
>
> Homer
> Homer
>
> Is this change a bug or intentional?
>
> Thanks,
> Andrew N.
> drender@bigsky.net
> andrew@neuschwander.org
>
>
>
--
Zeev Suraski <zeev@zend.com>
http://www.zend.com/