PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
function Hi ( $name )
{
_log( __FUNCTION__, func_get_args());
return 'Hi ' . $name;
}
What I'm looking for is some way to set up a "listener" that will log function call every time some (any) function is called. Something equivalent to set_error_handler()???
I was wondering if there's more intelligent way of logging in function calls as opposed to this
Nope.
What I'm looking for is some way to set up a "listener" that will log function call every time some (any) function is called. Something equivalent to set_error_handler()???
If your goal here is to get more information about the cause of errors. You may find Exceptions (PHP 5) are what you are after. If you throw an exception it takes with it a stacktrace which shows all the various calls that have lead it to that point. As it comes in PHP you get some pretty rubbish output, but if you go and download Pretty Blue Screen from sitepoint you get an excellent debugging system which I am making extensive use of currently.
Thanks for recomandation. We're on PHP 4.3 so exceptions are not usefull for me, set_error_handler was just an example. My goal is to log every function call regardless if an error had occured or not. What I want to see in my log file is every function that's been called, with the parameters passed to it and possibly functions return value. I was told PERL was capable of doing that so I'm hoping PHP is as well.
debug_backtrace would work as well, however what I'm trying to avoid is to hardcode a call to debug_backtrace or error_log within each one of my function calls.
Is it possible to "silently" call debag_backtrace or error_log or ... every time any function is executed without hardcoding it within each function body? For example set_error_handler("errorHandler") is called every time an error occurs regardless of where or who caused it. What I'm looking for is something along these lines. For example
set_any_function_handler("debug_backtrace");
Thanks for taking your time to answer my questions. I greatly appreciate it.
Is it possible to "silently" call debag_backtrace or error_log or ... every time any function is executed without hardcoding it within each function body?
I can say with total certainity that you cannot without some very very creative code that would preprocess your code and add in the necessary log calls to each function body.
I had another idea that you could call a_logged() when a() is defined catch the error in the callback for set_error_handler() and make the corrected call after having logged it but that doesn't work because calling an undefined function is a fatal error.
The only other suggestion I have for you it to modify PHP do to this, i imagine it wouldn't be difficult if you are familiar with the PHP source or you know someone who is. Of course that's a big if. The preprocessing is your best option.
XDebug is awesome. But.. it's also quite complicated (understatement of the day). I actually find it more useful for profiling code than debugging stuff.