Heim  >  Artikel  >  Backend-Entwicklung  >  php method_exists 检测类中是否包括函数_PHP教程

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

WBOY
WBOYOriginal
2016-07-20 11:02:351435Durchsuche

 

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() 函数的作用...
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn