php中怎样获取类的所有方法
小编给大家分享一下php中怎样获取类的所有方法,希望大家阅读完这篇文章后大所收获,下面让我们一起去探讨吧!
php获取类的所有方法的方法:可以利用get_class_methods()函数来获取。get_class_methods()函数返回由类的方法名组成的数组,如果失败则返回NULL。
get_class_methods()函数返回由类的方法名组成的数组。
语法:
array get_class_methods ( mixed $class_name )
返回由 class_name 指定的类中定义的方法名所组成的数组。如果出错,则返回 NULL。
注意:从 PHP 4.0.6 开始,可以指定对象本身来代替 class_name。
(视频教程推荐:php视频教程)
例如:
<?php$class_methods = get_class_methods($my_object); // see below the full example?>
代码示例:
<?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中怎样获取类的所有方法有了一定的了解,想了解更多相关知识,欢迎关注亿速云行业资讯频道,感谢各位的阅读!
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。