Jump to content

Function Name


watagal

Recommended Posts

Why would you want to do THAT? The name of a function is always known in advance, so why don't you simply

function getSomething() {echo 'getSomething';}

?If there's something more to it, at worse you can add a variable at the top of the function, and use that later in the function, like:

function getSomething() {$functionName = 'getSomething';echo $functionName;}

Link to comment
Share on other sites

Thanks for the quick response, but I won't know the function name at run time.Case: I have a many functions ("1","2","3") calling one function "A". Within function "A", I would like to determine the calling function ("1","2","3"). Clear as mud?TIA, Gal

Link to comment
Share on other sites

Oh. That's a completely different thing.If the function is within a class, you can adjust a property before calling the function to show the name of the last function called, or... I don't know. Whatever the scenario, you can probably do this without actually finding the name of the caller method.You could also pass an argument to the function made explicitly for the purpose. For example:

function getSomething($caller) {echo $caller;}function callGetSomething() {getSomething('callGetSomething');}

Link to comment
Share on other sites

I would do something like keeping record where i am with a session variable, like this:$_SESSION['last_visited'] = 'function_name';not as pretty as trying to pick it with some PHP variable or something like that, but still works.

Link to comment
Share on other sites

If by any chance you're debugging, you can always drop in a lot of temporary echo statements to keep tabs on what's what before things break. Probably you know that.icon1.gif

Link to comment
Share on other sites

isnt what u mean just the __METHOD__ constant?

function something(){	 echo "function name: ".__METHOD__;}something();

will show:function name: something

Link to comment
Share on other sites

your not making it clear to as what it is you need!i think this may help tho?

<?phpfunction getSomething($call1,$call2,$call3) {if ($call1 == "eg") {echo "$call2";}}?>

???

Link to comment
Share on other sites

glad it is, you can also use the __FUNCTION__ one, the difference is that __FUNCTION__ always just shows the function name, __METHOD__ will show it as classname::functionname if the function is i a class

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...