diff --git a/language/error-handling.xml b/language/error-handling.xml index 04d09dad7c71..9ba168fe274f 100644 --- a/language/error-handling.xml +++ b/language/error-handling.xml @@ -261,6 +261,13 @@ A custom function for this type of exception @ operator. + + + Prior to PHP 8.0.0 it was possible to suppress critical diagnostics that + would terminate the execution of the PHP script. + + + Diagnostics can be added, removed, have their severity altered or be diff --git a/language/operators.xml b/language/operators.xml index 0f543453bb06..117a00efa4a3 100644 --- a/language/operators.xml +++ b/language/operators.xml @@ -1848,16 +1848,41 @@ echo $foo ?? $bar ?? $baz ?? $qux; // outputs 1 Error Control Operators - PHP supports one error control operator: the at sign (@). When - prepended to an expression in PHP, any error messages that might - be generated by that expression will be ignored. - - - If you have set a custom error handler function with - set_error_handler then it will still get - called, but this custom error handler can (and should) call error_reporting - which will return 0 when the call that triggered the error was preceded by an @. + PHP supports one error control operator: the at sign (@). + When prepended to an expression in PHP, any diagnostic error that might + be generated by that expression will be suppressed. + + If a custom error handler function is set with + set_error_handler, it will still be called even though + the diagnostic has been suppressed, as such the custom error handler should + call error_reporting and verify that the + @ operator was used in the following way: + + + + +]]> + + + + + + + Prior to PHP 8.0.0, the value of the severity passed to the custom error + handler was always 0 if the diagnostic was suppressed. + This is no longer the case as of PHP 8.0.0. + + + Any error message generated by the expression is available in the "message" element of the array returned by error_get_last. @@ -1883,23 +1908,23 @@ $value = @$cache[$key]; - The @-operator works only on - expressions. A simple rule - of thumb is: if you can take the value of something, you can prepend - the @ operator to it. For instance, you can prepend it to variables, - function and include calls, constants, and - so forth. You cannot prepend it to function or class definitions, + The @-operator works only on + expressions. + A simple rule of thumb is: if one can take the value of something, + then one can prepend the @ operator to it. + For instance, it can be prepended to variables, functions, + include calls, constants, and so forth. + It cannot be prepended to function or class definitions, or conditional structures such as if and &foreach;, and so forth. - Currently the "@" error-control operator prefix will even disable - error reporting for critical errors that will terminate script - execution. Among other things, this means that if you use "@" to - suppress errors from a certain function and either it isn't - available or has been mistyped, the script will die right there + Prior to PHP 8.0.0, it was possible for the @ operator + to disable critical errors that will terminate script execution. + For example, suppressing a function which did not exist, by being + unavailable or mistyped, would cause the script to die with no indication as to why. diff --git a/reference/errorfunc/functions/set-error-handler.xml b/reference/errorfunc/functions/set-error-handler.xml index d4431c11a48d..8420d63649e0 100644 --- a/reference/errorfunc/functions/set-error-handler.xml +++ b/reference/errorfunc/functions/set-error-handler.xml @@ -32,11 +32,18 @@ error handler will be called regardless - however you are still able to read the current value of error_reporting and act - appropriately. Of particular note is that this value will be 0 if the - statement that caused the error was prepended by the - @ error-control - operator. + appropriately. + + + + Prior to PHP 8.0.0, the errno value was always + 0 if the expression which caused the diagnostic + was prepended by the + @ error-control operator. + + + Also note that it is your responsibility to die if necessary. If the error-handler function returns, script execution @@ -186,6 +193,14 @@ + + 8.0.0 + + errno is no longer 0 when + the expression was suppressed by the + @ error-control operator + + 8.0.0