FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Function that returns name of itself?
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Function that returns name of itself? [message #169455 is a reply to message #169454] Mon, 13 September 2010 18:23 Go to previous messageGo to previous message
matt[1] is currently offline  matt[1]
Messages: 40
Registered: September 2010
Karma:
Member
On Sep 13, 2:21 pm, matt <matthew.leonha...@gmail.com> wrote:
> On Sep 13, 1:18 pm, MikeB <mpbr...@gmail.com> wrote:
>
>
>
>> is there a function that one can use in (for example) an echo or print
>> command for debugging that will return the name of the function?
>
>> For instance
>
>> <?php
>
>> function abc(){
>>     echo my_name_is();
>>     return 0;
>
>> }
>
>> function def(){
>>    echo my_name_is();
>>     return 2;}
>
>> <?
>
>> I guess I could hardcode the function name in the echo statement, but I
>> like messing around. :)  I did look at php.net for a while  but couldn't
>> find anything.
>
> Try debug_backtrace().  Or more specifically
>
> function xxx()
> {
>   /* 0 index is top of the stack, which I kinda don't like, when you
>    * think about pushing and popping on a call stack...
>    */
>   $me = array_shift(debug_backtrace());
>   echo $me['function'];
>
> }
>
>

Doh! I should actually read the manuals for the functions I suggest!
You can also use __FUNCTION__, which is by far much simpler :)
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Job opening at RNT Labs Chandigarh
Next Topic: Something I have never seen before
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Nov 10 17:13:19 GMT 2024

Total time taken to generate the page: 0.04204 seconds