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

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


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

Example:

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

Result: MethodA.


You can use the magic constants __METHOD__ (includes the class name) or __FUNCTION__ (just function name) depending on if it's a method or a function... =)


If you are using PHP 5 you can try this:

function a() {    $trace = debug_backtrace();    echo $trace[0]["function"];}