简体   繁体   中英

How to pass method name as a parameter in PHP

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

Use magic constant FUNCTION

 function foo(){
  bar(__FUNCTION__);
 }

Additionall use

 __METHOD__ to get the name of a method

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM