phpfunction

How do I get the function name inside a function in PHP?


Is it possible?

function test()
{
  echo "function name is test";
}

Solution

  • The accurate way is to use the __FUNCTION__ predefined magic constant.

    Example:

    class Test {
        function MethodA(){
            echo __FUNCTION__;
        }
    }
    

    Result: MethodA.