建站软件 优化软件 编程软件 网页辅助 站群程序 网站程序 图像处理 资源教程 字体下载 推荐软件


您的位置:首页 > PHP学习 > php怎么检测类中是否有函数method_exists

php怎么检测类中是否有函数method_exists

时间:2015-05-17 20:17:39  来源:免费模板网 作者:风雪 阅读次数 tagsphp函数

 
封装好的一个类怎么查看里面是否包含函数呢,这时候可以用到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的对象属性是不区分大小写的

本文地址:https://www.freemoban.com/php/2015/0517/1830.html

猜你喜欢
栏目推荐
模板推荐

Copyright:www.freemoban.com 免费模板网 All Rights Reserved 网站备案:辽ICP备19014872号-2   辽公网安备 21010602000376号  辽公网安备:42900402000182号

免责声明:本站部分资源来自互联网收集,版权归原创者所有,如果侵犯了你的权益,我们会及时删除侵权内容,联系QQ:1615187561 谢谢合作!