-
Notifications
You must be signed in to change notification settings - Fork 764
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
trigger_error will terminate script #3694
Comments
The documentation indeed does not explicitly state that the default error handler issues an exit(1) when $error_level is E_USER_ERROR. However, the behavior of the default PHP error handler for E_USER_ERROR includes terminating script execution. This is equivalent to calling exit(1) internally, as the process exits with a status code indicating an error. When E_USER_ERROR is triggered, the default error handler stops script execution. This is PHP's standard behavior for fatal errors, including user-defined fatal errors (E_USER_ERROR). The phrase "Passing E_USER_ERROR as the error_level is now deprecated. Throw an Exception or call exit() instead." does not explicitly mandate that exit(1) must be used. It allows for any exit status to be used. However, the convention in most programming practices is to use exit(1) or any non-zero status to indicate an error, while exit(0) indicates successful termination. The absence of exit(1) in the default handler documentation doesn't negate its behavior of script termination. When using custom handlers, this termination behavior must be manually handled. The statement in the documentation gives you the flexibility to choose the appropriate exit status code based on your application's needs. We have noticed that this matter is being discussed since 2011, on StackOverFlow. CONCLUSION:No, exit(1) is not automatically issued when $error_level is E_USER_ERROR if a registered error handler does not explicitly terminate the script. If you register a custom error handler using set_error_handler(), the default behavior of PHP (which terminates the script for E_USER_ERROR) is overridden. In this case, the custom error handler has full control over what happens, and PHP will not automatically terminate the script unless you explicitly call exit() or throw an uncaught exception in your error handler. Hope it helps. |
Unless I am misunderstanding the issue, the |
https://www.w3docs.com/learn-php/trigger-error.html trigger_error with E_USER_ERROR.
|
I indeed think it would |
in https://www.php.net/function.trigger-error there is no mention of an
exit(1)
being issued when$error_level
isE_USER_ERROR
by the default error handler.Also it would be helpful that it will not if a registerd error handler does not issue and
exit(1)
The text was updated successfully, but these errors were encountered: