The manual states:
"errcontext will contain an array of every variable
that existed in the scope the error was triggered in. User
error handler must not modify error context."
But do you know WHY you must not modify the error context?
It appears that errcontext is (in effect if not literally)
created by taking $GLOBALS and adding the non-global local
variables as additional entries in that array, then passing
the whole thing *by reference*.
(You can prove this to be true if you set up a custom error
handler and then print_r($errcontext) within it, because
$GLOBALS will be printed as a recursive array).
In other words, the language in the manual is misleading,
because errcontext is NOT a copy of the variables that
existed when the error WAS triggered, but rather is a
reference to the *existing LIVE variables* in the calling
script.
This includes superglobal variables like $_SERVER, $_POST,
$_GET, etc., as well as all user-defined variables in
scope.
The significance of that is that if you modify errcontext,
you will be modifying those other variables, not just for
the life of your error handling function, but for the life
of the calling script as well.
That doesn't matter if you plan to halt execution in your
error handling function, but it will lead to unexpected
behavior if you modify $errcontext and then return to the
program's normal flow after handling the error, because the
variables will stay modified. For example, if you unset
$_SERVER in your custom error handling function, it will
remain unset once the function is over and you have returned
to the page that generated the error.
This should be made clearer in the manual, starting by
marking errhandler with an ampersand (&) for passage by
reference in the "Parameters" section above, like
so:
handler ( int $errno, string $errstr [, string $errfile [,
int $errline [, array &$errcontext]]] )
----
Server IP: 208.69.120.35
Probable Submitter: 68.163.129.98
----
Manual Page -- http://www.php.net/manual/en/function.set-error-handl
er.php
Edit -- https://master
.php.net/note/edit/76025
Del: integrated -- h
ttps://master.php.net/note/delete/76025/integrated
Del: useless -- http
s://master.php.net/note/delete/76025/useless
Del: bad code -- htt
ps://master.php.net/note/delete/76025/bad+code
Del: spam -- https:/
/master.php.net/note/delete/76025/spam
Del: non-english --
https://master.php.net/note/delete/76025/non-english
Del: in docs -- http
s://master.php.net/note/delete/76025/in+docs
Del: other reasons-- https://mast
er.php.net/note/delete/76025
Reject -- https://mast
er.php.net/note/reject/76025
Search -- https://
master.php.net/manage/user-notes.php
--
PHP Notes Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php
|