note 97313 added to language.oop5.static
| From: | myselfasunder at gmail dot com | Date: | Wed, 14 Apr 2010 04:42:53 +0000 |
| Subject: | note 97313 added to language.oop5.static | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-168215@lists.php.net to get a copy of this message | ||
If you inadvertently call a non-static method in one class from another class, using $this in the
former will actually refer to the wrong class.
class CalledClass
{
function go()
{
print(get_class($this) . "\n");
return true;
}
}
class CallerClass
{
function go()
{
CalledClass::Go();
return true;
}
}
$obj = new CallerClass();
$obj->go();
// Output is "CallerClass" instead of "CalledClass" like it should be.
Dustin Oprea
----
Server IP: 208.69.120.55
Probable Submitter: 76.108.75.234
----
Manual Page -- http://www.php.net/manual/en/language.oop5.static.php
Edit -- https://master.php.net/note/edit/97313
Del: integrated -- https://master.php.net/note/delete/97313/integrated
Del: useless -- https://master.php.net/note/delete/97313/useless
Del: bad code -- https://master.php.net/note/delete/97313/bad+code
Del: spam -- https://master.php.net/note/delete/97313/spam
Del: non-english -- https://master.php.net/note/delete/97313/non-english
Del: in docs -- https://master.php.net/note/delete/97313/in+docs
Del: other reasons-- https://master.php.net/note/delete/97313
Reject -- https://master.php.net/note/reject/97313
Search -- https://master.php.net/manage/user-notes.php