Home  >  Article  >  Backend Development  >  对象引用问题

对象引用问题

WBOY
WBOYOriginal
2016-06-23 13:50:06879browse

class A{	public $foo = 1;}$a = new A();$b = $a;$b->foo = 2;echo $a->foo . "<br />";$c = new A();$d = & $c;$d->foo = 3;echo $c->foo;

$b=$a 和 $d=&$c 有什么区别啊,这里用不用 & 都没什么不同


回复讨论(解决方案)

= 传值
=& 传引用
对象总是以 引用 传递的
所以对于对象 = 和 =& 没有区别

= 传值
=& 传引用
对象总是以 引用 传递的
所以对于对象 = 和 =& 没有区别


今天再看发现不对劲,但应该是有区别的吧?
<?phpclass A{}$a = new A();$b = &$a;$c = $a;$a = null;var_dump($a);var_dump($b);var_dump($c);

输出:NULL NULL object(A)#1 (0) { }
$c也应该为null才对啊??
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn