Re: Re: Fw: Identify which function called another

From: Date: Thu, 13 Jan 2005 05:06:43 +0000
Subject: Re: Re: Fw: Identify which function called another
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-206273@lists.php.net to get a copy of this message
Ben Ramsey wrote:
Lars B. Jensen wrote:
Is there any way, I from one function can identify which other function called it, without parameter passing the name manually ?
I still question whether its correct to design a function which requires this. I thought the idea of encapsulating code inside a function is that its non-dependent/black-boxed.... still for every rule there is an exception!
Please don't post twice in an hour if you haven't yet received your answer. With that in mind, I have an answer for you. :-)
maybe Lars thought his post had disappeared into /dev/null, not altogether strange considering the fluctuating time delays in posts being sent out! then maybe he's an impatient s.o.b ;-)
Use debug_backtrace(): http://www.php.net/debug-backtrace Harry Fuecks has an excellent post on how to use debug_backtrace() here: http://www.sitepoint.com/blog-post-view.php?id=157007
He has a lot of those (excellent posts that is), but he is really giving an example of debugging not writing code that relies on a debug_ function. I don't think debug_backtrace() should be used like this, having said that it will work - but I can only imagine that its a heavy function to call (because it has to 'analyse' the stack in order to return alot of info, nearly all of which is not needed in the case Lars presented)

« previous php.general (#206273) next »