How to get name of calling function/method in PHP?

Dawid Ohia picture Dawid Ohia · Jan 21, 2010 · Viewed 233.5k times · Source

I am aware of function debug_backtrace, but I am looking for some ready to use implementation of function like GetCallingMethodName()? It would be perfect if it gave method's class too (if it is indeed a method).

Answer

diyism picture diyism · Jun 28, 2012

The simplest way is:

echo debug_backtrace()[1]['function'];