[thelist] PHP -- get name of calling function?

Stephen Rider evolt_org at striderweb.com
Tue Jul 29 17:04:27 CDT 2008

Hi --

Is there any way in PHP to get the name of the function that called  
the one you're in right now?

In other words:

function hello() {
	$x = goodbye();

function goodbye() {
	$y = get_calling_func();  // $y should equal "hello"


If the two functions are in different files, is there any way for the  
second to figure out what file the first was in?

Basically, I'm trying to get __FILE__ and __FUNCTION__ for hello()  
from within goodbye().
The hard part is that any number of functions might be calling  
goodbye() -- I need to figure out which one.

The purpose of all this is that I want deprecated functions to log  
what other functions are calling them, so coders can easily see where  
they need to go in and update deprecated stuff to the current  
functions.  Thus, calls to goodbye() will log something like:

deprecated function "goodbye" was called by "hello" in <filename>.

This is for part of a system that for now should still work with PHP  
4.  :-\

Thanks Much!


Stephen Rider

More information about the thelist mailing list