note 29265 deleted from language.oop by aidan
| From: | aidan@php.net | Date: | Sat, 03 Jul 2004 14:54:10 +0000 |
| Subject: | note 29265 deleted from language.oop by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-72450@lists.php.net to get a copy of this message | ||
Note Submitter: twoch
----
As noted in another section of this user manual, the variable $this refers to the innermost
encompassing class.
If you invoke a method on class A from and instance of A, and from within that method invoke a
method in class B using the "::" syntax (i.e. invoked as a class method), if the method
within B uses $this it will refer to the instance of class A that called it.
Note that this behavior is very different from the case where the same B method is invoked using and
instance of class B, in which case $this refers to the instance of class B.
This can cause no end of grief when trying to debug such object methods that were invoked as class
methods (although it can also be a powerful tool when used correctly). However, IMHO, any method
that might be invoked as a class method should refrain from the use of $this.