站长资讯网
最全最丰富的资讯网站

php如何获取类的所有方法

php获取类的所有方法的方法:可以利用get_class_methods()函数来获取。get_class_methods()函数返回由类的方法名组成的数组,如果失败则返回NULL。

php如何获取类的所有方法

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

赞(0)
分享到: 更多 (0)

网站地图   沪ICP备18035694号-2    沪公网安备31011702889846号