Class Person {
Public $name;
protected $age;
Public function __construct ($name, $age) {
$this->name = $name;
$this->age = $age;
}
}
$LH = new Person (' Emily Lau ', 23);
$a = $LH;
$b =& $lh;
-------------------------------------------------------------------------
What is the difference between $ A and $b? Can be analyzed from the perspective of the memory stack.
··
Reply content:
There is no need to add & quote symbols in PHP. All objects are reference passes, unless you explicitly call clone $object laxatives
===============
I forgot which version to start with, and I don't need to add & quote symbols in PHP.
Add the will report a grammatical error, this detailed answer, you can ask @ Hantian (he also answered).
Or ask @Laruence Uncle Bird the Danale.
Assigning a value to a variable of a basic type of sauce, usually a true copy (understood as: 2 pointers, pointing to 2 memory spaces).
$a = 100;$b = $a;unset($a);echo $b."\n";
There are some differences, in your case, if you assign a new value to B, the direction of LH will also change, but a will not have this problem.
The reference in the PHP manual is:
Note:
$a and $b is completely equal here. $a is not pointing to $b or vice versa. $a and $b is pointing to the same place.
The arguments to objects and references in PHP5 are:
A PHP Reference is an alias, which allows and different variables to write to the same value. As of PHP 5, an object variable doesn ' t contain the object itself as value anymore. It is only contains a object identifier which allows object accessors to find the actual object. When an object was sent by argument, returned or assigned to another variable, the different variables was not aliases:the Y hold a copy of the identifier, which points to the same object.
In fact, the object variable take & more like a pointer to the pointer.
@ Li Huaizhi I also remember that PHP does not need to add & quote symbols, are reference delivery. But after my test (PHP5.6.7), I was puzzled by the following:
class Person { public $name = 'myName';}$obj = new Person;$assign = $obj;$reference = & $obj;$obj = null;//此操作很重要var_dump($obj);//得到nullvar_dump($assign);//得到object(Person)#1 (1) {["name"]=>string(6) "myName"}var_dump($reference);//得到null
Baidu a bit exactly the same