Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Professional PHP Blog:
Of PHP References and Compatibility
Oct 21, 2005 @ 10:44:09

From the Professional PHP Blog today, there's a look at "the problem with taking a reference of $this".

The best summary is in this bug report.

It comes down to the fact that allowing references to be taken of $this can lead to unexpected values for $this later on. ($this re-assigned) However, it does not appear that a good solution exists:

Given the choice between: (A) doing nothing but leaving room for confusion, (B) taking away the ability to create references, or (C) checking assignments for references to $this(read: slow); The current decision is to go with (A).

He makes the point that a Warning from PHP would be enough in a situation like this, but, for now, it still throws a Fatal error. He also mentions this article from Derick Rethans concerning references as an excellent, enlightening read.

tagged:

Link:


Trending Topics: