errorfunc: document the error handler stack - #5253
Merged
lacatoire merged 1 commit intoAug 25, 2026
Merged
Conversation
lacatoire
force-pushed
the
fix/error-handler-stack-semantics
branch
4 times, most recently
from
August 25, 2026 20:04
781a5ac to
5212897
Compare
set_error_handler() saves the handler that was active until then on an internal stack and installs the new one in its place; restore_error_handler() pops the saved one back, together with the error_levels mask it was registered with. Neither page said so, which invites restoring the previous handler by passing the return value of set_error_handler() back to it. That grows the stack instead of shrinking it, and resets error_levels to E_ALL. Adds a caution against that pattern and an example calling the previous handler from the new one. The seealso simplelists are unwrapped from their para, matching the exception handler pages.
lacatoire
force-pushed
the
fix/error-handler-stack-semantics
branch
from
August 25, 2026 20:09
5212897 to
4e46d36
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
set_error_handler()saves the handler that was active until then on an internal stack and installs the new one in its place;restore_error_handler()pops it back, together with theerror_levelsmask it was registered with. Neither page said so, which invites passing the return value ofset_error_handler()back to it to "restore" it — that pushes a further entry instead of removing one, and silently resetserror_levelstoE_ALL.Both pages now describe the save/restore mechanism, the
nullcase and the empty-stack case. A caution warns against the re-registration pattern, and an example calls the previous handler from the new one. Theseealso<simplelist>are unwrapped from their<para>, matching the exception handler pages.The exception handler side is left out: it behaves differently since 8.3.5 and those pages already document it.
Sources:
ZEND_FUNCTION(set_error_handler)andZEND_FUNCTION(restore_error_handler)inZend/zend_builtin_functions.c;user_error_handleranduser_error_handlersinZend/zend_globals.h;shutdown_executor()inZend/zend_execute_API.c, which releases the stacks at the end of the request.Fixes: #4883