Home > php教程 > php手册 > body text

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

WBOY
Release: 2016-06-02 09:14:18
Original
1203 people have browsed it

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();
Copy after login

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

本文地址:

转载随意,但请附上文章地址:-)

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template