Is there a difference between $a =new A and $a = & new?
$a =new A; $a is a copy of the pointer to new A ($a holds the pointer itself)
$a =& new A; $a is a reference to a pointer to new A ($a holds the address of the pointer)
Is that the right thing to say?
Other than that:
When $c = & $a, why does the $a also become a reference to the pointer of a?
------Solution--------------------
When $c = & $a, why does the $a also become a reference to the pointer of a?
is in $a =& new A;?
------Solution--------------------
Hee,& in C is the access character
------Solution--------------------
PHP variables are pointers, but for string,int and so on, assignment = is a copy of the object, for the object, assignment = is a copy of the address (that is, reference), I now feel that it is very good to understand.
------Solution--------------------
Whatever version of PHP the new operator produces is a reference
$a =& new A;
This is not an accurate notation. Assign a reference to an object to a variable?
So in php5.3, a new error type was added to standardize the writing format.
Deprecated:assigning The return value of new by reference is Deprecated
php5.2 and previously did not error, but does not mean that it is not wrong.
Just as you blocked the E_notice level error, but you can not say that there is no mistake, after all, the use of undefined variables or subscript it
------Solution--------------------
It's a tangled question.
------Solution--------------------
The Orthodox usage
$c = new A;
It is a nonsense to use other usages.
------Solution--------------------
Well, look at the cow's blog.
Http://www.laruence.com/2008/09/19/520.html
Explaining your problem on the 6 floor.
------Solution--------------------
Check the manual:
About references:
Referencing in PHP means accessing the same variable content with a different name. This is not like the C pointer, instead, the reference is the symbol table alias. Note that in PHP, variable names and variable contents are not the same, so the same content can have different names. The closest analogy is the Unix filename and the file itself-the variable name is the directory entry, and the variable content is the file itself. References can be seen as hardlink in Unix file systems.
About NEW:
Construct An instance of "type" and store the reference to the "object" into "result".
So $c = new A; Is an assignment reference, not a copy of the object. $c = &new A; is the wrong wording.
Since PHP 5, new automatically returns references, so using =& here is obsolete and generates E_STRICT-level messages.
------Solution--------------------
About Assignment:
Note that the assignment operation copies the value of the original variable into a new variable (value assignment), so changing one does not affect the other. This is also suitable for copying some values such as large arrays in a very dense loop. You can also use reference assignment, with $var = & $othervar; Grammar. A reference assignment means that both variables point to the same data, without any copy of the data. For more information on references, see the description of the reference. In PHP 5, objects are always assigned by reference, unless the new clone keyword is explicitly used.
PHP Code
Foo = 2;echo "OA: $oa->foo, ob: $ob->foo\n";?>
------Solution--------------------
$a = 1;
$b = & $a;
Different variables point to the same address, and when one ($b =2) changes, the other changes ($a =2). But after destroying the $b (unset ($b)) $a = 2 still exists.
$a = 1;
$b = $a;//he is $b=1.
= = $a =1; $b = 1;
$b $a not a dime of the relationship, you are you I am me, who does not matter who.