inactive Posted April 29, 2009 Share Posted April 29, 2009 Hey homies, Is there anyway in the function I set in set_error_handler() to return true, and die? My code: <?php set_error_handler('my_error_handler'); function my_error_handler($errno, $errstr, $errfile, $errline) { // ... handle error here ... // } echo 1/0; // generates a warning trigger_error('Some Other Error', E_USER_ERROR); // generates user error ?> What the my_error_handler() function does will depend on the error type: 1) In the case of the warning, after handling the error, it will return true, so that the normal PHP error handler will log the error in the normal error log, and then it will let the rest of the script proceed. This works great. 2) In the case of the user error, I need it to handle the error, then return true, so that the normal PHP error handler will log the error in the normal error log, and then exit. I cannot get this to work. ??? Is there a way to return true, and exit/die? If I don't exit/die, the rest of the script will continue to run, with detrimental results. If I do exit, then it is not possible to return true, which means the error won't be logged properly by the normal PHP error handler. I.e: <?php exit(); // script will exit, return true; // but will not return true (obviously, as the script has already terminated) ?> <?php return true; // script will return true, exit(); // but as it has now jumped out of this function, will now not exit ?> Any ideas? Is this even possible? Thanks in advance. Quote Link to comment Share on other sites More sharing options...
Mchl Posted April 29, 2009 Share Posted April 29, 2009 Why should it return true if it is to exit anyway? See example for set_error_handler. They show how to distinguish between different error types. Quote Link to comment Share on other sites More sharing options...
inactive Posted April 29, 2009 Author Share Posted April 29, 2009 The PHP internal error handler will not be executed unless the error handling function returns true. I need this to happen. Returning true, false, not returning anything has no effect on the actual script itself. See the example here: http://au.php.net/manual/en/function.set-error-handler.php Quote Link to comment Share on other sites More sharing options...
Mchl Posted April 29, 2009 Share Posted April 29, 2009 It's the other way round... If the function returns FALSE then the normal error handler continues. Quote Link to comment Share on other sites More sharing options...
inactive Posted April 29, 2009 Author Share Posted April 29, 2009 It's the other way round... If the function returns FALSE then the normal error handler continues. Ah yes I beg your pardon, you are correct. *** I need it to return false, and die/exit. *** Quote Link to comment Share on other sites More sharing options...
Mchl Posted April 29, 2009 Share Posted April 29, 2009 The script is halted on E_USER_ERROR anyways. http://www.php.net/manual/en/errorfunc.constants.php Quote Link to comment Share on other sites More sharing options...
inactive Posted April 29, 2009 Author Share Posted April 29, 2009 Good point. Maybe I don't need to worry about this at all... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.