O'Reilly PHP Cookbook in error?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I was looking in _PHP Cookbook_ by David Sklar and Adam Trachtenberg
from O'Reilly. On page 155  under "Assigning Object References" it
says, "Problem: You want to link two objects, so when you update one,
you update the other. Solution: Use =& to assign one object to another
by reference ... When you do an object assignment using =, you create a
new copy of an object ... But when you use =&, the two objects point at
each other."

I thought that when you use =& the thing on the left is a *variable*,
not an object, and that it points to the thing on the right, which is
usually an object. There is no "pointing at each other".

In the PHP manual
(http://www.php.net/manual/en/language.references.whatdo.php ), they go
to great lengths to specifically emphasize this distinction...

$a =& $b;

it means that $a and $b point to the same content.

Note: $a and $b are completely equal here, that's not $a is pointing to
$b or vice versa, that's $a and $b pointing to the same place.

Is the book just wrong, or am I not understanding this correctly?

I would be interested to hear others' comments.



Re: O'Reilly PHP Cookbook in error?

elektrophyte wrote:

Quoted text here. Click to load it

Yes - this is semantically incorrect.

It would be more correct to say that the two variables reference the same
instance of (the object or variable).


Site Timeline