note 115822 deleted from language.constants.predefined by peehaa

From: Date: Mon, 22 May 2017 07:24:56 +0000
Subject: note 115822 deleted from language.constants.predefined by peehaa
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-209083@lists.php.net to get a copy of this message
Note Submitter: user at NOSPAM dot example dot com ---- __CLASS__ has caused me some confusion before. If you extend from a class that calls __CLASS__ in a function, __CLASS__ will refer to the parent class and not the extending class. <?php class A { function sayClassFromObjectA() { echo "<br/>This is class " . __CLASS__; } } class B extends A { function sayClassFromObjectB() { echo "<br/>This is class " . __CLASS__; } } $b = new B(); //I expect it to output "This is class B". $b->sayClassFromObjectA(); //Outputs "This is class A" //I expect it to output "This is class B". $b->sayClassFromObjectB(); //Outputs "This is class B" ?>

« previous php.notes (#209083) next »