本教程操作环境:windows7系统、PHP7.1版、DELL G3电脑php获取方法名称使用魔术常量__FUNCTioN____FUNCTION__:当前函数(或方法)的名称;<?php header("Content-t
本教程操作环境:windows7系统、PHP7.1版、DELL G3电脑
php获取方法名称
使用魔术常量__FUNCTioN__
__FUNCTION__:当前函数(或方法)的名称;
<?php
header("Content-type:text/html;charset=utf-8");
class WEBsite {
public function demo() {
echo '成员方法名'.__FUNCTION__;
}
}
$student = new Website();
$student -> demo();
?>
2、使用魔术常量__METHOD__
__METHOD__:当前的方法名(包括类名);返回该方法被定义时的名字(区分大小写)。
<?php
header("Content-type:text/html;charset=utf-8");
class Website {
public function demo() {
echo '类名+方法名'.__METHOD__;
}
}
$student = new Website();
$student -> demo();
?>
3、get_class_methods()函数
get_class_methods — 获取类的所有的方法名,并且组成一个数组
get_class_methods(mixed $class_name): array
返回由 class_name 指定的类中定义的方法名所组成的数组。如果出错,则返回 null。
示例:
<?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 <br>";
}
?>
--结束END--
本文标题: php怎么获取方法名称
本文链接: https://www.lsjlt.com/news/1231.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0