xingfang Posted March 18, 2016 Share Posted March 18, 2016 Hello,recently, the company needed an PHP script to capture error,i try to use “set_error_handler”,but it can’t capture fatal error,like redeclare a function,then I try to change a way that use “register_shutdown_function”,but I found it that also unable to capture above mentioned errors at the end of the script. my php version is 7.0.1 Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted March 18, 2016 Share Posted March 18, 2016 (edited) First off: Why do you want to capture fatal errors? When the application code is fudged up, there's obviously nothing you could do about that at runtime. Or do you just want to display a user-friendly error message instead of the infamous blank page? Then you should set up a custom error page in the webserver configuration. You cannot catch compile-time errors (like a duplicate declaration) by registering an error handler at runtime, because that code never gets executed. It's theoretically possible to register the handler before the script is compiled (e. g. through an auto-prependend file). But there's no reason to do that except for very exotic scenarios. Edited March 18, 2016 by Jacques1 Quote Link to comment Share on other sites More sharing options...
xingfang Posted March 19, 2016 Author Share Posted March 19, 2016 I see your replies, the moment I wake up. Quote Link to comment Share on other sites More sharing options...
MarkLeci Posted March 26, 2016 Share Posted March 26, 2016 I agree with Jacques, for things like redeclaring a function you should be either using a custom page (or catching them in testing). I'm wondering if you could set display_errors(0) in your page or php.ini file, and catch things in your code with something like this (obviously this will vary depending on what the error you want to catch is and what your expected behaviour is). if(function()) { //your usual code } else { some error } This is risky though, because as well as hiding the error you want, you're hiding other errors in the page (or the whole site if you use the ini file) 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.