Is it possible to do something like this?
public function something() {
$thisMethodName = method_get_name(); // I made that function up, but is there some way of doing what it describes?
}
Thanks
Is it possible to do something like this?
public function something() {
$thisMethodName = method_get_name(); // I made that function up, but is there some way of doing what it describes?
}
Thanks
Why can't you do this?
public function something() {
$thisMethodName = "something";
}
Sure, you want the magic constants.
function myFunction() { print __FUNCTION__." in ".__FILE__." at ".__LINE__."\n"; }
Find out more from the php manual
Hackish, but you could also probably dig it out of the debug_backtrace() return value.
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.
I think aswering such questions should include some mentoring. _ FUNCTION _ is supposed to be used in debugging purposes. Using it in other cases in questionable. I suggest author to describe the task he wants to achieve with this "do I know what my name is" thing. And we will help him invent some more acceptable solution.
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'.