首页 > 开发 > PHP > 正文

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

2024-05-04 21:59:21
字体:
来源:转载
供稿:网友

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. $obj = new a(); 
  10. var_dump(method_exists($obj'xx')); 
  11. var_dump(method_exists($obj'xx')); 
  12. var_dump(method_exists($obj'xx')); 
  13. //测试结果都为true 
  14. //开源软件:Vevb.com 
  15. class a { 
  16.     public function xx(){ 
  17.         echo 'xx'
  18.     } 
  19.      
  20.     public function yy() { 
  21.         echo 'yy'
  22.     } 
  23.     public function yy() { 
  24.         echo 'yy'
  25.     } 
  26. $obj = new a(); 
  27. $obj->yy(); 
  28. $obj->yy(); 

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

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表