【发布时间】:2010-07-31 10:15:25
【问题描述】:
是否可以在运行时重命名 PHP 5.2 中的类方法?是否可以使用反射来做到这一点?
给定:
class Test
{
public function myMethod()
{
echo 'in my method';
}
}
我希望能够将 myMethod() 重命名为 oldMethod(),以便稍后我这样做:
$test = new Test();
$test->oldMethod(); // in my method
$test->myMethod(); // run time error: method does not exist
【问题讨论】:
-
你到底想做什么,需要贴一些代码。
-
PHP 运行时[重命名函数]的可能重复项。 ](stackoverflow.com/questions/2846353/…)
-
你打算通过重命名一个方法来达到什么目的?重命名方法的基本原理是什么? __call() 可能是另一种选择。
-
这味道。你为什么需要这个?
-
@Gordon:因为我想在类上安装调用事件处理程序,而类不知道它,所以我会知道用户正在调用类中的方法 before i> 这个方法实际上被调用了。
标签: php reflection