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
method_exists 找不到子类中的方法顺序。
如何让它发挥作用?
最佳答案
__CLASS__
绑定(bind)到它所使用的类,而不是继承类。您可以通过使用 $this
作为对象引用来解决这个问题。
另见 http://www.php.net/manual/en/language.oop5.late-static-bindings.php .
关于PHP method_exists 不适用于类(class) child ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5700197/