1234;
echo "nObject $B after operation:n";
var_dump($B);
echo "nObject $A implicitly modified after operation:n";
var_dump($A);
echo "nObject $C implicitly modified after operation:n";
var_dump($C);
$A = new y;
$A->d = 25200;
echo "nObject $B after $A modification:n";
var_dump($B); echo "nObject $A after $A modification:n";
var_dump($A);
echo "nObject $C implicitly modified after $A modification:n";
var_dump($C); ?>
Thus, note the difference between assignments $X = $Y and $X =& $Y.
When $Y is anything but an object instance, the first assignment means
that $X will hold an independent copy of $Y, and the second, means that
$X and $Y will refer to the same thing, so they are tight together until
either $X or $Y is forced to refer to another thing. However, when $Y
happens to be an object instance, the semantic of $X = $Y changes and
becomes only slightly different to that of $X =& $Y, since in both
cases $X and $Y become references to the same object. See what this
example outputs:
Object $A before operation:
object(y)#1 (1) {
["d"]=>
int(18)
}
Object $B after operation:
object(y)#1 (1) {
["d"]=>
int(1234)
}
Object $A implicitly modified after operation:
object(y)#1 (1) {
["d"]=>
int(1234)
}
Object $C implicitly modified after operation:
object(y)#1 (1) {
["d"]=>
int(1234)
}
Object $B after $A modification:
object(y)#1 (1) {
["d"]=>
int(1234)
}
Object $A after $A modification:
object(y)#2 (1) {
["d"]=>
int(25200)
}
Object $C implicitly modified after $A modification:
object(y)#2 (1) {
["d"]=>
int(25200)
}
Let's review a SECOND EXAMPLE:
<?php
class yy {
public $d;
function yy($x) {
$this->d = $x;
}
}
function modify
10/12 首页 上一页 8 9 10 11 12 下一页 尾页 |