Re: Re: PHP 4.0 Bug #3647 Updated: Change to Global variablein Function Fails
| From: | Andreas Pour | Date: | Thu, 01 Jun 2000 17:22:39 +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-19982@lists.php.net to get a copy of this message | ||
Stanislav Malyshev wrote:
>
> AP>> You have to be kidding me!?!? This is still a bug. The variable was
>
> No, I'm not kidding you and this is not a bug. Declaring variable as
> "global" makes local variable to be pointing to global one (like, $var =
> &$GLOBALS["var"]). Unsetting this local one is unsetting this local one,
> but the global one doesn't vanish. However, if you change it, global value
> gets changed, because local one is pointing to global one. But, if you
> assign to it a new reference, old one gets removed, so you again might not
> get what you expect. I know, this is not easy to understand, but that's
> the way references work in PHP now.
Ahhh, thanks for the clarification. I did not know that a GLOBAL
declaration is treated as a reference; I thought you would directly
access the global variable. From reading
'language.variables.scope.html' one does not become aware of this
distinction (i.e., that $GLOBALS["a"] !== GLOBAL $a).
>
> You can read Andi's article on reference counting at
> http://www.zend.com/zend/art/ref-count.php
> to get more understanding of this. Or read the source (not for the faint
> of heart).
I understand reference counting; I just was not aware that a GLOBAL
declaration gives you a reference rather than the real thing. Obviously
it was not that way in PHP3 as there were no reference assignments in
PHP3 :-).
>
> AP>> declared as GLOBAL, so I shouldn't have to use the $GLOBALS array to set
> AP>> *or* *unset* it.
>
> Well, you can try and sue PHP Group over violation your rights not to use
> $GLOBALS, but this is how it presently works in PHP.
To be fair, I'm not talking about suing, I filed a bug report :-).
> If you don't like it,
> submit feature/change request. I just trying to hel you to make it work
> now.
I appreciate that. Perhaps this can be changed into a documentation bug
report ;-). OTOH, I think a lot of people will get bitten by this
design implementation, so perhaps people will consider having a GLOBALy
declared variable directly access the GLOBALS hash table.
Thanks,
Andreas