php红怎么查看类的方法
这篇文章主要介绍php红怎么查看类的方法,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
要想查看php中类的方法,我们可以利用get_class_methods()方法来实现。该函数可以返回由类的方法名组成的数组,例如:【get_class_methods($my_object)】。
get_class_methods — 返回由类的方法名组成的数组。
说明
array get_class_methods ( mixed $class_name )
返回由 class_name 指定的类中定义的方法名所组成的数组。如果出错,则返回 NULL。
注意: 从 PHP 4.0.6 开始,可以指定对象本身来代替 class_name,例如
<?php $class_methods = get_class_methods($my_object); // see below the full example?>
(学习视频推荐:php视频教程)
举例:
<?phpclass myclass{ // constructor function myclass() { return (true); } // method 1 function myfunc1() { return (true); } // method 2 function myfunc2() { return (true); }} $class_methods = get_class_methods('myclass'); // or$class_methods = get_class_methods(new myclass());foreach ($class_methods as $method_name){ echo "$method_name";}
输出:
myclassmyfunc1myfunc2
以上是php红怎么查看类的方法的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注亿速云行业资讯频道!
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。