DatsunBing
DatsunBing

Reputation: 9076

How to pass method name as a parameter in PHP

In PHP, if method foo() calls method bar($name), can it pass it's method name (i.e. 'foo') as a parameter?

Upvotes: 0

Views: 110

Answers (1)

SoWhat
SoWhat

Reputation: 5622

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

Upvotes: 4

Related Questions