对象引用问题
Jun 23, 2016 pm 01:50 PM
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才对啊??

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to use block quotes in Apple Notes

Convert an array or object to a JSON string using PHP's json_encode() function

C++ compilation error: undefined reference, how to solve it?

How to convert MySQL query result array to object?

What are the benefits of C++ functions returning reference types?

Use Python's __contains__() function to define the containment operation of an object

Use Python's __le__() function to define a less than or equal comparison of two objects
