Posted by Jim Michaels on 09/30/01 11:37
I would agree that & is a modifier. if $a were truly converted from real
data into a reference the data would have been destroyed by modifying the
RHS. That's illegal in a language parser. I was speaking more about the
internal representation and the way the parser probably works. & just says
"give me the address of $a". Maybe I am misunderstanding what you are trying
to say.
"Chung Leong" <chernyshevsky@hotmail.com> wrote in message
news:1137347700.332528.316130@g14g2000cwa.googlegroups.com...
> Jim Michaels wrote:
>> This doesn't sound technically correct. an operator (such as =& ) in a
>> parser is generally never allowed to modify the RHS (right-hand-side).
>> This
>> jives with the article he mentioned.
>
> In a way the term "reference" is unfortunate. In C++ being a reference
> is a variable's intrinsic, whereas in PHP a variable "is a reference"
> if the data it points to is shared--an external condition.
>
> One could argue that there is no changes on the right-hand-side of an
> assignment if = and & are treated as separate operators and any
> side-effect is caused by the latter. You can put white spaces between
> the two after all. On the other hand, & is really just a modifier and
> we have just one operator even with white spaces. In any event, a
> couple changes can occur on the right-hand-side of a =&:
>
> 1. $b =& $a makes both $b and $a references. This is actually perfectly
> logical: since $a and $b are point to the same data, $a can be used to
> modify what's in $b--hence it is a reference. It's only funky from the
> C/C++ perspective, as the type of $a has suddenly changed.
>
> 2. Autovivication is triggered.
>
> Example:
>
> <?php
> error_reporting(E_ALL);
> $b = &$a['Goodbye']['cruel']['world']->letter;
> print_r($a);
> ?>
>
> Result:
>
> Array
> (
> [Goodbye] => Array
> (
> [cruel] => Array
> (
> [world] => stdClass Object
> (
> [letter] =>
> )
>
> )
>
> )
>
> )
>
[Back to original message]
|