判断php中的方法是否存在的方法:可以使用method_exists函数来进行判断,如【method_exists($directory,'read')】。如果要判断类中的属性是否已定义,可以使用property_exists函数判断。
相关函数:
(学习视频推荐:java课程)
bool method_exists ( mixed $object , string $method_name ) 检查类的方法是否存在
代码示例:
$directory=new Directory; if(!method_exists($directory,'read')) { echo '未定义read方法!'; }如果要判断类里面的某个属性是否已经定义,在使用如下方法:
bool property_exists ( mixed $class , string $property )检查类的属性是否存在
代码示例:
$directory=new Directory; if(!property_exists($directory,'li')) { echo '未定义li属性!'; }相关推荐:php培训
以上就是判断php中的方法是否存在该怎么做的详细内容!
查看更多关于判断php中的方法是否存在该怎么做的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://www.haodehen.cn/did53166
判断php中的方法是否存在该怎么做
阅读:46次