How to catch undefined functions with set_error_handler in PHP

后端 未结 6 496
一整个雨季
一整个雨季 2021-02-05 19:47

I\'m taking the leap: my PHP scripts will ALL fail gracefully!

At least, that\'s what I\'m hoping for...`

I don\'t want to wrap (practically) every single line i

6条回答
  •  情话喂你
    2021-02-05 20:46

    Very interesting thing that I've discovered today as I was facing the similar problem. If you use the following - it will catch the error with your custom error handler function / method:

    ini_set('display_errors', 'Off');
    error_reporting(-1);
    
    set_error_handler(array("Cmd\Exception\Handler", "getError"), -1 & ~E_NOTICE & ~E_USER_NOTICE);
    

    By setting 'display_errors' to 'Off' you can catch still catch them with the handler.

提交回复
热议问题