note 29265 added to language.oop

From: Date: Fri, 07 Feb 2003 18:38:24 +0000
Subject: note 29265 added to language.oop
Groups: php.notes 
Request: Send a blank email to php-notes+get-43577@lists.php.net to get a copy of this message
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. -- http://www.php.net/manual/en/language.oop.php http://master.php.net/manage/user-notes.php?action=edit+29265 http://master.php.net/manage/user-notes.php?action=delete+29265 http://master.php.net/manage/user-notes.php?action=reject+29265

« previous php.notes (#43577) next »