Re: Getting the name of a function
| From: | tedd | Date: | Wed, 27 Feb 2008 19:22:43 +0000 |
| Subject: | Re: Getting the name of a function | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-270369@lists.php.net to get a copy of this message | ||
At 10:56 AM -0800 2/27/08, Richard S. Crawford wrote:
For my own amusement, I'm writing a function that will print out detailed error messages for an API that I'm creating for a minor project. One of the pieces of information I'd like to return would be the name of the function that called the error function. For example: <?php function error ($message) {Try get_defined_functions() Also, remember __LINE__ and __FILE__ They help a lot to find out where something went wrong. Cheers, tedd -- ------- http://sperling.com http://ancientstones.com http://earthstones.comprint "The error message is $message"; print "The function that called the error was: [INSERT COOL CODE HERE]";} function bad_function($param) {error ("This is dumb"); return false;} bad_function("blah"); ?> Ideally this script would print this out: The error message is This is dumb The function that called the error was bad_function I know that I could pass the name of the function as a parameter to the error() function (e.g. error("bad_function","This is dumb")) but I'd rather keep it simpler than that. Is there a way to do this?