Posted by Chung Leong on 09/28/34 11:37
Jerry Stuckle wrote:
> Actually, not. In C++ a reference is a different type of variable.
>
> int i = 4; // the real thing
> int & j = i; // a reference to i.
>
> The second statement does NOT change i in any way. the same is true in PHP:
>
> $i = 4;
> $j = & $i;
>
> $i is an value; $j is a reference to the value.
That's a common misconception about references in PHP. I suggest
reading the article that Tim referred to earlier.
> No, there is no change in $i when you assign a reference to it.
I am afraid you're arguing with reality here. To illustrate...
<?php
$obj->i = 5;
debug_zval_dump($obj);
$obj->j =& $obj->i;
debug_zval_dump($obj);
?>
Result:
object(stdClass)(1) refcount(2){
["i"]=>
long(5) refcount(1)
}
object(stdClass)(2) refcount(2){
["i"]=>
&long(5) refcount(2)
["j"]=>
&long(5) refcount(2)
}
Navigation:
[Reply to this message]
|