PHP 7.0 + can handle fatal errors without terminating PHP process.
It means we can catch the fatal error using
catch
block
try {
undefinedFunction();
} catch (Error $e) {
echo 'Fatal error occurred: ' . $e->getMessage();
}
After running the above code on PHP 7+ the result will be:
Fatal error occurred: Call to undefined function undefinedFunction()
If we run the same code on PHP 5.6, we will get the following result:
<br />
<b>Fatal error</b>: Call to undefined function undefinedFunction() in <b>[...][...]</b> on line <b>5</b><br />