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

php

Question

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).

1
193
2/3/2016 9:49:00 PM

Accepted Answer

The debug_backtrace() function is the only way to know this, if you're lazy it's one more reason you should code the GetCallingMethodName() yourself. Fight the laziness! :D

133
1/21/2010 4:13:12 PM

The simplest way is:

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

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon