|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2002-07-19 11:50 UTC] duncan at emarketeers dot 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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Dec 31 13:00:02 2025 UTC |
This WAS really NOT a bogus bug! It is solved though in PHP 4.3.4 (or earlier in 4.3.x?). We have exactly the same - incorrect - behaviour when setting our own error handler in PHP 4.2.3. The following test case shows this clearly. 1) NO user defined error handler: <?php $c = "some text"; $a = $b . trim($c); echo "a="; echo $a; ?> This code produces the output a=some text 2) WITH user defined error handler: <?php function ourOwnErrorHandler() { } $old_error_handler = set_error_handler("ourOwnErrorHandler"); $c = "some text"; $a = $b . trim($c); echo "a="; echo $a; ?> This code produces the output a= This was tested on: PHP Version 4.2.3 System Linux 2.4.1 #1 SMP Thu Oct 25 16:10:32 CEST 2001 i686 unknown Build Date Sep 20 2002 12:00:27 Configure Command './configure' '--with-config-file-path=/usr/local/apache/conf' '--with-apache=/usr/local/src/apache' '--with-jpeg-dir=/usr/local/src/jpeg-6b' '--with-png-dir=/usr/local/lib' '--with-zlib-dir=/usr/local/lib' '--with-zlib' '--with-gd=/usr/local/src/gd' '--with-oci8=/u01/app/oracle/product/8.1.7' '--with-oracle=/u01/app/oracle/product/8.1.7' '--enable-dbase' '--with-mcrypt' '--with-mhash' '--with-imap' Joop Vriend.