class parent{
function run($methodname) {
echo method_exists(__CLASS__, $methodname);
}
}
class child extends parent {
function order(){
echo 'hello';
}
}
$test = new child();
$test->run('order'); //false
The method_exists cannot find the method order in child class.
How to make it work?
__CLASS__
is bound to the class it's used in, not to inheriting classes. You can solve this by using $this
as the object reference.
Also see http://www.php.net/manual/en/language.oop5.late-static-bindings.php.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With