Here's what I want to do just if a fatal error is in the file I don't want the script to halt execution
try {
require "somethin.php"
} catch(...) {}
Would some method of file_get_contents()
and eval()
be a way around
Here's what I want to do just if a fatal error is in the file I don't want the script to halt execution
try {
require "somethin.php"
} catch(...) {}
Would some method of file_get_contents()
and eval()
be a way around
Notice - this does not answer the poster's question. The ugly reality is you cannot recover from a fatal error but this works for other errors
require doesn't throw an exception but rather triggers an error by default.
To have php throw exceptions you have to register an error exception handler.
You can find an example here
But basically it
function exception_error_handler($errno, $errstr, $errfile, $errline ) {
throw new ErrorException($errstr, $errno, 0, $errfile, $errline);
}
set_error_handler("exception_error_handler");
With this in play it's possible to catch and deal with the error as you see fit
No there is really no sane way to catch (uncatchable ;-) ) fatal errors in PHP. So there is also no sane way to recover from this. Which makes sense because it is a fatal error.
Basically what PHP is saying is: this is something you cannot / should not try to recover from.
Note that also @Orangepill's solution won't work for fatal errors: http://codepad.org/4nzzYQSG
Now if you would want to do something when a fatal error happens (e.g. send an email to you to inform you of this) you may want to look into: https://stackoverflow.com/a/2146171/508666