如何在PHP中将方法名称作为参数传递


How to pass method name as a parameter in PHP

在PHP中,如果方法foo()调用方法bar($name),它能将其方法名称(即"foo")作为参数传递吗?

使用魔术常数FUNCTION

 function foo(){
  bar(__FUNCTION__);
 }

额外使用

 __METHOD__ to get the name of a method

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