ID:               18437
 Comment by:       joop dot vriend at ddnh dot nl
 Reported By:      duncan at emarketeers dot com
 Status:           Bogus
 Bug Type:         Scripting Engine problem
 Operating System: Linux
 PHP Version:      4.2.1
 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------

[2002-07-26 08:51:43] duncan at emarketeers dot com

I would have thought that an error handler which doesn't 
catch errors has a bug in it.

------------------------------------------------------------------------

[2002-07-24 19:48:43] [EMAIL PROTECTED]

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.



------------------------------------------------------------------------

[2002-07-24 08:42:58] duncan at emarketeers dot 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] [EMAIL PROTECTED]

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 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

------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=18437&edit=1

Reply via email to