Can a PHP function dynamically know its name?
<p>I'm trying to get a list of functions that have already run in the context of an operation. And that's where the need arised. </p>

<p>Is there a way to get something like this work?</p>

<pre><code>function funcX()
{
    echo this.nameOrSomethingHere; //outputs funcX
} 
</code></pre>

<p>As <a href="http://stackoverflow.com/questions/1013239/can-i-get-the-name-of-the-currently-running-function-in-javascript">this example</a> demonstrates, it is possible to achieve this functionality in  Javascript. </p>

<p>I can always go for an alternative solution for taking care of my original need like with an alternative way around as follows;</p>

<pre><code>function funcX()
{
    $this_function_name = "funcX";
    Add_this_to_the_already_executed_functions_list($this_function_name);     
} 
</code></pre>

<p>And here, the Add_this_to_the_already_executed_functions_list functions job is to take the passed string and add it to a globally defined array so at the end of the shutdown process you can get a view of all the functions that have been run in the last page. </p>

<p>The above method would work, but, obviously, it's not elegant cause it's not dynamic. </p>

<p>It would have been nice to be able to do something like this</p>

<pre><code>function funcX()
{
     Add_this_to_the_already_executed_functions_list(this.????);     
} 
</code></pre>

<p>The question is if there is a way to do this in PHP? </p>
