gpt4 book ai didi

PHP method_exists 不适用于类(class) child ?

转载 作者:可可西里 更新时间:2023-11-01 12:31:05 24 4
gpt4 key购买 nike

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com