1) Use debug_trace() or debug_print_trace()
Example:
debug_trace();
exit();
This will yield you with all the functions called, the arguments passed to the functions and the references to where they where called.
2) Throw an exception
Example:
throw new Exception('just debugging')
Throwing an exception will halt the application and by default print debugging information similar to the above. The only difference is that you don't have to call another exit command to prevent the script from continuing execution.
In relation to that above, I have seen programmers relying on vigorous, manual work to locate a PHP code problem by using simple methods like print_r, print or echo with an exit code following the command to debug. This is not a bad thing, in fact I do it to myself often. There are however smarter ways to do it for more complex applications which rely on libraries and modules which have better programming design patterns infused to the code than the early-2000 way of one-page-has-everything technique which is still newbie mistake even on the year 2011.
There are ways to be smarter in terms of debugging PHP to boost your productivity many folds. Explore use of IDE debuggers, PHP extension debuggers such DBG, Xdebug, Advance PHP debugger (http://www.php.net/manual/en/debugger-about.php), things like ZFDebug and FirePHP. It's a topic worth discussing in another article. :)
No comments:
Post a Comment