Reputation: 139862
Is it possible?
function test()
{
echo "function name is test";
}
Upvotes: 277
Views: 153195
Reputation: 29
<?php
class Test {
function MethodA(){
return __FUNCTION__ ;
}
}
$test = new Test;
echo $test->MethodA();
?>
Result: "MethodA";
Upvotes: 2
Reputation: 29322
The accurate way is to use the __FUNCTION__
predefined magic constant.
Example:
class Test {
function MethodA(){
echo __FUNCTION__;
}
}
Result: MethodA
.
Upvotes: 452
Reputation: 2447
If you are using PHP 5 you can try this:
function a() {
$trace = debug_backtrace();
echo $trace[0]["function"];
}
Upvotes: 20
Reputation: 45721
You can use the magic constants __METHOD__
(includes the class name) or __FUNCTION__
(just function name) depending on if it's a method or a function... =)
Upvotes: 107