2

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.

Is there a way to get something like this work?

function funcX()
{
    echo this.nameOrSomethingHere; //outputs funcX
} 

As this example demonstrates, it is possible to achieve this functionality in Javascript.

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

function funcX()
{
    $this_function_name = "funcX";
    Add_this_to_the_already_executed_functions_list($this_function_name);     
} 

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.

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

It would have been nice to be able to do something like this

function funcX()
{
     Add_this_to_the_already_executed_functions_list(this.????);     
} 

The question is if there is a way to do this in PHP?

Community
  • 1
  • 1
Average Joe
  • 4,521
  • 9
  • 53
  • 81

3 Answers3

10

You can use __FUNCTION__ to get the current function's name.

alex
  • 479,566
  • 201
  • 878
  • 984
0

http://us2.php.net/manual/en/function.debug-backtrace.php

debug_backtrace will tell you that and a lot more. best for debugging, but you could use it for whatever you wanted.

dldnh
  • 8,923
  • 3
  • 40
  • 52
0

Use __FUNCTION__

See 'magic constants'

Daan Timmer
  • 14,771
  • 6
  • 34
  • 66