Trying to debug PHP using its default current-line-only error messages is horrible. How can I get PHP to produce a backtrace (stack trace) when errors are produced?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
As php debug extensions, there is Xdebug and PHP DBG. Each one has its advantages and disadvantages.
This is how you do it:
It requires PHP 5.3+ since it uses a closure. If you need lower PHP support just convert the closure to a normal function.
My script for installing an error handler that produces a backtrace:
Caveat: it is powerless to affect various 'PHP Fatal Errors', since Zend in their wisdom decided that these would ignore
set_error_handler()
. So you still get useless final-location-only errors with those.Xdebug prints a backtrace table on errors, and you don't have to write any PHP code to implement it.
Downside is you have to install it as a PHP extension.
i wrote a little article about backtracing a while back
PHP DeBugger also does a back trace similiar to PHP Error with more options.
If you want you can easily make your own with
set_error_handler
anddebug_backtrace
Also note that for internal stacks in the backtrace some of the keys will not be set. Be sure to check if the key exist before you do something with it if you have all errors on :)