php获取类的所有方法可以利用get_class_methods()函数来实现,该函数可以返回由类的方法名组成的数组,如果出错则返回NULL。函数语法:【get_class_methods($class_name)】。

php为我们提供了一个函数get_class_methods,该函数可以返回由类的方法名组成的数组,如果出错则返回 NULL。
(推荐视频教程:php视频教程)
语法:
array get_class_methods ( mixed $class_name )
(相关推荐:php培训)
立即学习“PHP免费学习笔记(深入)”;
代码示例:
<?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号