Re: Re: PHP 4.0 Bug #3647 Updated: Change to Global variablein Function Fails
| From: | Stanislav Malyshev | Date: | Thu, 01 Jun 2000 16:25:02 +0000 |
| Subject: | Re: Re: PHP 4.0 Bug #3647 Updated: Change to Global variablein Function Fails | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-19986@lists.php.net to get a copy of this message | ||
AP>> I understand reference counting; I just was not aware that a GLOBAL
AP>> declaration gives you a reference rather than the real thing. Obviously
AP>> it was not that way in PHP3 as there were no reference assignments in
AP>> PHP3 :-).
Actually, every variable is a reference now, that's the meaning of
"reference counting mechanism". That means, this also won't get what you'd
expect:
<?
function f() {
global $foo;
unset($GLOBALS["foo"]);
var_dump($foo);
}
$foo = 1;
f();
?>
this will still print 1, because though you've destroyed reference in
GLOBALS array, the local reference is still valid. In fact, this thing is
very consistent, though it is not always works as you would expect. It
works not unlike filesystem on unix - most cases, you erase it and file
goes away, but not so with hardlinks, and .. and . are even weirder :)
AP>> report ;-). OTOH, I think a lot of people will get bitten by this
AP>> design implementation, so perhaps people will consider having a GLOBALy
Well, people need to start understanding this if they try to get into such
fields.
--
Stanislav Malyshev stas@zend.com
+972-3-6139665