tags:

views:

147

answers:

2

Is there a function that can return the name of the current function a program is executing?

+7  A: 

Yes you can with

__FUNCTION__

class trick
{
  function doit()
  {
            echo __FUNCTION__;
  }
  function doitagain()
  {
            echo __METHOD__;
  }
}

$obj=new trick();
$obj->doit();
output will be ----  doit
$obj->doitagain();
output will be ----- trick::doitagain

More info here....

Sarfraz
Awesome. Magic constants! I wasn't sure if there were variables for this but there are. This will save me a lot of code, thank you.
Cian E
@cianestro: you welcome, thank you :)
Sarfraz
A: 

Maybe via debug_backtrace http://www.php.net/manual/en/function.debug-backtrace.php

robertbasic
-1 - magic constants are proper way to do this.
Crozin