Re: [PHP4BETA] unset and global behavior problems.
[email protected] (Zeev Suraski)
| Newsgroups | php.version4 |
|---|---|
| Message-ID | <[email protected]> |
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.
> [email protected]
> [email protected]
>
>
>
--
Zeev Suraski <[email protected]>
http://www.zend.com/