giles
giles

Reputation:

returning a method name

I'm using the following as a way of seeing listing the various methods in my developement

print basename(__FILE__) . "::serve_table()"

is there any function that's able to return the name of a class method so I don't have to trpe it each time?

Upvotes: 2

Views: 193

Answers (3)

grepsedawk
grepsedawk

Reputation: 6059

Use __FUNCTION__ and __LINE__ and __CLASS__ and __METHOD__

Upvotes: 8

Davide Gualano
Davide Gualano

Reputation: 12993

I'm not understanding if you need a way to list all the methods of a class or if you need to retrieve the method name you have just called.

If the former, using reflection:

$class = new ReflectionCLass("classname");
$methods = $class->getMethods();
foreach($methods as $m)
    print $m->getName();

Upvotes: 1

Konrad Rudolph
Konrad Rudolph

Reputation: 546183

You could use the information provided by debug_backtrace which provides the stack trace in an array.

Upvotes: 2

Related Questions