Bug #18437 Updated: Return value from custom error handler passed back to calling script

From: Date: Wed, 24 Jul 2002 23:48:43 +0000
Subject: Bug #18437 Updated: Return value from custom error handler passed back to calling script
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-15098@lists.php.net to get a copy of this message
ID: 18437 Updated by: sniper@php.net Reported By: duncan@emarketeers.com -Status: Open +Status: Bogus Bug Type: Scripting Engine problem Operating System: Linux PHP Version: 4.2.1 New Comment: Sorry, but the bug system is not the appropriate forum for asking support questions. Your problem does not imply a bug in PHP itself. For a list of more appropriate places to ask for help using PHP, please visit http://www.php.net/support.php Thank you for your interest in PHP. Previous Comments: ------------------------------------------------------------------------ [2002-07-24 08:42:58] duncan@emarketeers.com Glad to see it works in an unstable alpha. But on a production release it is broken. You do trigger those error levels. You get E_NOTICE passed through to the error handler when e.g. you try to reference an undefined variable, as in the example. Even though you didn't ask for it. While we're on the subject, why can't user error-handlers catch E_ERROR? If I'm in the middle of a complicated database transaction I'd at least like the chance to be able to tidy up. ------------------------------------------------------------------------ [2002-07-19 12:33:58] sniper@php.net This is the output with PHP 4.3.0-dev: "This fails: some text <br>But this works: some text <br>" (I don't understand your example..you never trigger those error levels..) ------------------------------------------------------------------------ [2002-07-19 11:50:12] duncan@emarketeers.com If you set an error handler which returns rather than dying, then the return value of the handler is passed back to the script in place of the expected value iff the statement which raised the error is followed by a function call. Additionally, execution of the remainder of the statement is aborted. This means that e.g. if you reference an unset variable as part of an expression which contains function calls, the expression will evaluate to the return value of the error handler, which is NOT the behaviour if you have not got an error handler installed. i.e. the following will print This fails: --ERROR-- <br> But this works: some text <br> <? function myErrorHandler ($errno, $errstr, $errfile, $errline) { switch ($errno) { case E_USER_ERROR: { echo "A fatal error occurred"; exit; } default : { } } return "--ERROR--"; } define (FATAL,E_USER_ERROR); define (ERROR,E_USER_WARNING); define (WARNING,E_USER_NOTICE); // set the error reporting level for this script error_reporting (FATAL | ERROR | WARNING); set_error_handler("myErrorHandler"); $c = "some text"; $a = $b . trim($c); echo "This fails: $a <br>"; $a = $b . $c; echo "But this works: $a <br>\n"; ?> My config line was: ./configure --with-xslt-sablot --enable-xslt --with-mysql --enable-mailparse --enable-mbstring ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=18437&edit=1

« previous php.bugs (#15098) next »