如何在PHP中使用方法名称作为参数

问题描述:

在PHP中,如果方法foo()调用方法栏($ name),是否可以将它的方法名称(即'foo')作为参数传递?如何在PHP中使用方法名称作为参数

+0

你会意识到,一个方法需要一个对象,对不对? – 2012-02-07 02:19:25

+0

你的意思是一个函数,而不是一个正确的方法?一个方法基本上是一个功能,它是一个对象的一部分 – 2012-02-07 02:20:14

使用魔法不断功能

function foo(){ 
    bar(__FUNCTION__); 
} 

Additionall使用

__METHOD__ to get the name of a method 

http://php.net/manual/en/language.constants.predefined.php