Florian Müller
Florian Müller

Reputation: 7785

PHP: Get actual function name

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!

Upvotes: 0

Views: 5461

Answers (5)

T.Todua
T.Todua

Reputation: 56351

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?

Upvotes: 0

K6t
K6t

Reputation: 1845

Yo can try....

__FUNCTION__

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

Upvotes: 2

Fake Code Monkey Rashid
Fake Code Monkey Rashid

Reputation: 14547

<?php

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

?>

Upvotes: 4

plandolt
plandolt

Reputation: 1931

It is possible. Use this:

echo __FUNCTION__;

Upvotes: 1

Aabaz
Aabaz

Reputation: 3116

You should check PHP predefined constants: magic constants

Upvotes: 1

Related Questions