当前位置:首页 > PHP教程 > php应用 > 列表

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

发布:smiling 来源: PHP粉丝网  添加日期:2014-09-18 21:44:31 浏览: 评论:0 

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

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

method_exists() 函数的作用是检查类的方法是否存在,如果 method_name 所指的方法在 object 所指的对象类中已定义,则返回 true,否则返回 false,实例代码如下:

  1. class a { 
  2.     public function xx(){ 
  3.         echo 'xx'; 
  4.     } 
  5.      
  6.     public function yy() { 
  7.         echo 'yy'; 
  8.     } 
  9. } 
  10. $obj = new a(); 
  11. var_dump(method_exists($obj, 'xx')); 
  12. var_dump(method_exists($obj, 'xx')); 
  13. var_dump(method_exists($obj, 'xx')); 
  14. //测试结果都为true 
  15. //开源软件:phpfensi.com 
  16. class a { 
  17.     public function xx(){ 
  18.         echo 'xx'; 
  19.     } 
  20.      
  21.     public function yy() { 
  22.         echo 'yy'; 
  23.     } 
  24.     public function yy() { 
  25.         echo 'yy'; 
  26.     } 
  27. } 
  28. $obj = new a(); 
  29. $obj->yy(); 
  30. $obj->yy(); 

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

Tags: method_exists php检测类函数

分享到: