Reputation:
Is a parse error an EXAMPLE of an error that OCCURS BEFORE THE SCRIPT IS EXECUTED?
https://www.php.net/manual/en/errorfunc.configuration.php#ini.error-reporting
Although display_errors may be set at runtime (with ini_set()), it won't have any effect if the script has fatal errors. This is because the desired runtime action does not get executed.
https://www.php.net/manual/en/function.set-error-handler.php
If errors occur before the script is executed (e.g. on file uploads) the custom error handler cannot be called since it is not registered at that time.
My doubt is because in 2 cases PHP mentions the term "before executing".
Upvotes: 1
Views: 202
Reputation: 97718
PHP is not a directly interpreted language: your source code is processed first by a compiler. Specifically, when you tell PHP to execute a file, or include it with include
/require
, the entire file is parsed and compiled to an intermediate representation called "OpCodes". Only once the entire file has been compiled does any code in that file get executed (by running the OpCodes through an interpreter).
For that compilation to succeed, the syntax of the entire file needs to be correct. If it is not, a Parse Error will be generated.
If you are including a file, that error can be caught by the file which is calling include
or require
. But if the file being compiled is the one directly invoked by the web server or command-line command, there is no code "outside" that file which could catch the error, or change the settings relating to its display or handling.
When any error is not handled, PHP's last resort is simply to end the process - this is what is referred to as a "fatal error". In this case, the error can't be handled, so is always fatal; in most other cases, there is a chance to handle the error, and it only becomes fatal if you do not.
Upvotes: 1