How can I get PHP to produce a backtrace upon errors?

后端 未结 11 2133
無奈伤痛
無奈伤痛 2020-11-28 23:29

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?

11条回答
  •  一个人的身影
    2020-11-29 00:13

    This is how you do it:

    set_error_handler(function($errorType){
        if(error_reporting() & $errorType){
            ?>

    It requires PHP 5.3+ since it uses a closure. If you need lower PHP support just convert the closure to a normal function.

提交回复
热议问题