意题教育
您的当前位置:首页判断php中的方法是否存在该怎么做

判断php中的方法是否存在该怎么做

来源:意题教育


相关函数:

(学习视频推荐: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属性!';
}
显示全文