0

I got another problem: I'm just trying to make a nice and sweet log class, and now I'd also like to log the function name in which the program is.

But, to make it better code, is there a function to get the function name of the function which is just executing? It should look just as follows:

<?php
function test() {
    echo "We are in my function " . getFunctionName();
}
?>

And the output would be

We are in my function test()

Is something possible at all?

Thanks for help!

2
  • 1
    Typing your title in Google would've given you a solution in the first hit... Commented Sep 20, 2011 at 8:19
  • duplicate stackoverflow.com/questions/1006248/… Commented Jan 23, 2014 at 18:52

5 Answers 5

4
<?php

function test()
{
    echo "We are in my function " . __FUNCTION__;
}

?>
Sign up to request clarification or add additional context in comments.

Comments

2

Yo can try....

__FUNCTION__

http://www.php.net/manual/en/language.constants.predefined.php

Comments

1

You should check PHP predefined constants: magic constants

Comments

1

It is possible. Use this:

echo __FUNCTION__;

Comments

0

not __FUNCTION__, but only debug_backtrace()

works well, especially if function is included in parents!!!....

see: how to get function name inside a function in PHP?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.