当前位置:Gxlcms > PHP教程 > phpmethod_exists检测类中是否包括函数_PHP教程

phpmethod_exists检测类中是否包括函数_PHP教程

时间:2021-07-01 10:21:17 帮助过:2人阅读

php教程 method_exists 检测类中是否包括函数

method_exists() 函数的语法如下:bool method_exists ( object object, string method_name)


method_exists() 函数的作用是检查类的方法是否存在。


如果 method_name 所指的方法在 object 所指的对象类中已定义,则返回 true,否则返回 false

class a {
public function xx(){
echo 'xx';
}

public function yy() {
echo 'yy';
}
}

$obj = new a();

var_dump(method_exists($obj, 'xx'));
var_dump(method_exists($obj, 'xx'));
var_dump(method_exists($obj, 'xx'));

测试结果都为true

class a {
public function xx(){
echo 'xx';
}

public function yy() {
echo 'yy';
}

public function yy() {
echo 'yy';
}
}

$obj = new a();
$obj->yy();
$obj->yy();

以上语句报错。
今天才发现原来php的对象属性是不区分大小写的


www.bkjia.comtruehttp://www.bkjia.com/PHPjc/445353.htmlTechArticlephp教程 method_exists 检测类中是否包括函数 method_exists() 函数的语法如下:bool method_exists ( object object, string method_name) method_exists() 函数的作用...

人气教程排行