PHP父类的构造函数里面有办法判断子类有某个方法吗?
修正:应该使用method_exists()
;
实例代码如下:
<?php
class F{
public function __construct(){
if(method_exists($this, 'son_fun1')){
echo 'son_fun1存在';
}else{
echo 'son_fun1不存在';
}
if(method_exists($this,'son_fun2')){
echo 'son_fun2存在';
}else{
echo 'son_fun2不存在';
}
}
}
class S extends F{
public function son_fun1(){
}
}
$a = new S();
2 回答1.3k 阅读✓ 已解决
2 回答827 阅读✓ 已解决
1 回答918 阅读✓ 已解决
1 回答1k 阅读✓ 已解决
2 回答884 阅读
1 回答874 阅读
1 回答803 阅读
hongweipeng的代码有错误, $this应该改成$static.
不懂请google 后期静态绑定