note 97313 deleted from language.oop5.static by cmb

From: Date: Sun, 01 Sep 2019 07:26:07 +0000
Subject: note 97313 deleted from language.oop5.static by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-212051@lists.php.net to get a copy of this message
Note Submitter: myselfasunder at gmail dot com ---- 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. <?php 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

« previous php.notes (#212051) next »