Re: [PHP] Getting the name of a function
Daniel Brown schreef: On Thu, Feb 28, 2008 at 5:06 AM, Jochem Maas [EMAIL PROTECTED] wrote: Daniel Brown schreef: On Wed, Feb 27, 2008 at 1:56 PM, Richard S. Crawford [EMAIL PROTECTED] wrote: [snip!] 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? Not without a lower-level stack trace utility like xdebug, as far huh? what about debug_backtrace() ... contains plenty of info, including function names of everything in the stack. of course something like xdebug can take it to a whole new level. You're right. Forgot about that function. :-\ your forgiven, you've probably had a lot on your mind lately what with choosing a dress for the ceremony :-P -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Getting the name of a function
On Fri, Feb 29, 2008 at 7:44 AM, Jochem Maas [EMAIL PROTECTED] wrote: Daniel Brown schreef: On Thu, Feb 28, 2008 at 5:06 AM, Jochem Maas [EMAIL PROTECTED] wrote: huh? what about debug_backtrace() ... contains plenty of info, including function names of everything in the stack. of course something like xdebug can take it to a whole new level. You're right. Forgot about that function. :-\ your forgiven, you've probably had a lot on your mind lately what with choosing a dress for the ceremony :-P Oh, did I forget to mention that it's an open bar for everyone *except* you, and that you'll be paying a mere seven-times the price of normal drinks, with a 10 drink required minimum? ;-P -- /Dan Daniel P. Brown Senior Unix Geek ? while(1) { $me = $mind--; sleep(86400); } ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Getting the name of a function
Daniel Brown schreef: On Wed, Feb 27, 2008 at 1:56 PM, Richard S. Crawford [EMAIL PROTECTED] 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. [snip!] 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? Not without a lower-level stack trace utility like xdebug, as far huh? what about debug_backtrace() ... contains plenty of info, including function names of everything in the stack. of course something like xdebug can take it to a whole new level. as I know. However, you can slightly modify your code to do this: ?php function error ($func,$message) { print The error message is $message; print The function that called the error was: .$func.\n; } function bad_function($param) { error (__FUNCTION__,This is dumb); return false; } bad_function(blah); ? I also placed that online in my code library (to which I always forget to link, but have dozens of examples), along with a function to list all of the user-level functions available to the current script. [Demo]http://www.pilotpig.net/code-library/function-info.php [Source] http://www.pilotpig.net/code-library/source.php?f=function-info.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Getting the name of a function
On Thu, Feb 28, 2008 at 5:06 AM, Jochem Maas [EMAIL PROTECTED] wrote: Daniel Brown schreef: On Wed, Feb 27, 2008 at 1:56 PM, Richard S. Crawford [EMAIL PROTECTED] wrote: [snip!] 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? Not without a lower-level stack trace utility like xdebug, as far huh? what about debug_backtrace() ... contains plenty of info, including function names of everything in the stack. of course something like xdebug can take it to a whole new level. You're right. Forgot about that function. :-\ -- /Dan Daniel P. Brown Senior Unix Geek ? while(1) { $me = $mind--; sleep(86400); } ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Getting the name of a function
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) { print 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? -- Richard S. Crawford ([EMAIL PROTECTED]) http://www.mossroot.com Publisher and Editor in Chief, Daikaijuzine (http://www.daikaijuzine.com) Support me in Write-a-thon 2007: http://www.firstgiving.com/richardscrawford
Re: [PHP] Getting the name of a function
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) { print 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? 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.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Getting the name of a function
On Wed, Feb 27, 2008 at 1:56 PM, Richard S. Crawford [EMAIL PROTECTED] 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. [snip!] 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? Not without a lower-level stack trace utility like xdebug, as far as I know. However, you can slightly modify your code to do this: ?php function error ($func,$message) { print The error message is $message; print The function that called the error was: .$func.\n; } function bad_function($param) { error (__FUNCTION__,This is dumb); return false; } bad_function(blah); ? I also placed that online in my code library (to which I always forget to link, but have dozens of examples), along with a function to list all of the user-level functions available to the current script. [Demo]http://www.pilotpig.net/code-library/function-info.php [Source] http://www.pilotpig.net/code-library/source.php?f=function-info.php -- /Dan Daniel P. Brown Senior Unix Geek ? while(1) { $me = $mind--; sleep(86400); } ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php