在&= PHP对象分配中的目的

What is the exact purpose of a statement like this?

$myObj =& $existingObject

Is this extending $myObj with the properties and methods of $existingObject?

What does the equals sign (=) and the ampersand (&) married together here do?

Um first of all, &= and =& are two different things. Which is it?

  • &= is a bitwise and with the righthand side
  • =& is better written as = & (with a space), is assigning something as a reference.

$myObj becomes a reference to $existingObject instead of being copied. So any change to $myObj also changes $existingObject. (see this article)

This is a pass by reference. It means anything you do to $existingObject will also be done to $myObj because one is a reference to the other.

Based on the names of the variables, they are objects. Objects are always passed by reference, so = & would be redundant.