Search code examples
phpmethodsoop

Get method name from within the method in PHP


Is it possible to do something like this?

public function something() {
    $thisMethodName = method_get_name(); 
}

Where method_get_name() returns the name of the method itself.


Solution

  • Sure, you want the magic constants.

    function myFunction() { print __FUNCTION__." in ".__FILE__." at ".__LINE__."\n"; }
    

    Find out more from the php manual