再会!
我有一个问题,还没有具体的解决方案。我想检查该方法是否属于特定类。method_exists() 适用于所有可用的方法,但它应该在类上。那些。这是关于其中存在一种或另一种方法...
class firstClass {
public function firstMethod() {}
private function secondMethod() {}
}
class secondClass extends firstClass {
public function thirdMethod() {}
private function fourthMethod() {}
}
$obj = new secondClass;
$methodName = 'firstMethod';
if(method_exists($obj,$methodName)) {
}
更准确地说,我想在子类继承的情况下定义它。
先感谢您!
https://ideone.com/BERrFP
您可以使用 ReflectionClass 的hasMethod ( )方法