Can you get a method name from within a method in PHP?
While you can use the magic constant __METHOD__
I would highly recommend checking out PHP's reflection. This is supported in PHP5.
$modelReflector = new ReflectionClass(__CLASS__);
$method = $modelReflector->getMethod(__METHOD__);
You can then do kick-ass stuff like inspect the signature, etc.
As smartj suggested you can try the magic constant __METHOD__
, but remember that this will return a string containing also your class name, i.e. 'MyClass::something'.
Using __FUNCTION__
instead will return 'something'.
Sure, you want the magic constants.
function myFunction() { print __FUNCTION__." in ".__FILE__." at ".__LINE__."\n"; }
Find out more from the php manual