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

get_class_methods()函数返回由类的方法名组成的数组。
(推荐教程:php图文教程)
语法:
array get_class_methods ( mixed $class_name )
返回由 class_name 指定的类中定义的方法名所组成的数组。如果出错,则返回 NULL。
立即学习“PHP免费学习笔记(深入)”;
注意:从 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如何获取类的所有方法的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号