php获取类的所有方法的方法:可以利用get_class_methods()函数来获取。get_class_methods()函数返回由类的方法名组成的数组,如果失败则返回NULL。
get_class_methods()函数返回由类的方法名组成的数组。
(推荐教程:php图文教程)
语法:
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 ?>代码示例:
<?php class 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"; }输出结果:
myclass myfunc1 myfunc2以上就是php如何获取类的所有方法的详细内容!
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://www.haodehen.cn/did54738
php如何获取类的所有方法
阅读:46次