Posted by Chung Leong on 01/15/06 19:55
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]
|