PHP-在执行父函数时获取子类?
我不认为我在这里很傻PHP-在执行父函数时获取子类?,php,oop,inheritance,Php,Oop,Inheritance,我不认为我在这里很傻 class Parent { function load($function) { if (method_exists(__CLASS__, $function)) { // Load Function } } } Class Child extends Parent { function foo() { } } $this->Child->load('foo'); 问题是\uuuuuuuuuuuuuuuuuuu
class Parent {
function load($function) {
if (method_exists(__CLASS__, $function)) {
// Load Function
}
}
}
Class Child extends Parent {
function foo() {
}
}
$this->Child->load('foo');
问题是
\uuuuuuuuuuuuuuuuuuu类
正在返回“Parent”。如何让它返回孩子?您的问题的直接答案是:
但在您的情况下,为什么不简单地使用$this
作为方法_exists()的参数呢
啊,当然可以。非常感谢你的帮助。9分钟后会滴答响。
if (method_exists(get_class($this), $function)) {
if (method_exists($this, $function)) {