From:             php-bug at zulan dot net
Operating system: Win32
PHP version:      5.0.3
PHP Bug Type:     Zend Engine 2 problem
Bug description:  Error triggered in wrong scope for include

Description:
------------
When include or require (_once) triggers an error it is triggered in a
different "scope" as other errors, like an above funktion or the main
dummy function. Therfore when the error is handled by throwing an
exception instead this will give confusing results including uncaught
exceptions that actually should be caught.

Reproduce code:
---------------
<?php
function __error_handler($type, $message, $file, $line, $context)
{
    throw new Exception($message,$type);
}
set_error_handler('__error_handler',E_ALL);

function test($t) {
    try
    {
     /* Both should trigger the error in the same context */
        if ($t)
            include('missing_file.php');
        else
            fopen('forgot_parameter');
    }
    catch (Exception $e)
    {
        echo("Catched exception inside of
test():\n".$e->getMessage()."\n");
    }
}

try
{
    test(true);
}
catch (Exception $e)
{ /* So we do not get a nasty uncaught exception error */
     echo("Catched exception outside of
test():\n".$e->getMessage()."\n");
}

try
{
    test(false);
}
catch (Exception $e)
{ /* So we do not get a nasty uncaught exception error */
     echo("Catched exception outside of
test():\n".$e->getMessage()."\n");
}
?>

Expected result:
----------------
Catched both exceptions inside of test

Actual result:
--------------
Catches the fopen error inside but the include error outside of test.

-- 
Edit bug report at http://bugs.php.net/?id=32207&edit=1
-- 
Try a CVS snapshot (php4):   http://bugs.php.net/fix.php?id=32207&r=trysnapshot4
Try a CVS snapshot (php5.0): 
http://bugs.php.net/fix.php?id=32207&r=trysnapshot50
Try a CVS snapshot (php5.1): 
http://bugs.php.net/fix.php?id=32207&r=trysnapshot51
Fixed in CVS:                http://bugs.php.net/fix.php?id=32207&r=fixedcvs
Fixed in release:            http://bugs.php.net/fix.php?id=32207&r=alreadyfixed
Need backtrace:              http://bugs.php.net/fix.php?id=32207&r=needtrace
Need Reproduce Script:       http://bugs.php.net/fix.php?id=32207&r=needscript
Try newer version:           http://bugs.php.net/fix.php?id=32207&r=oldversion
Not developer issue:         http://bugs.php.net/fix.php?id=32207&r=support
Expected behavior:           http://bugs.php.net/fix.php?id=32207&r=notwrong
Not enough info:             
http://bugs.php.net/fix.php?id=32207&r=notenoughinfo
Submitted twice:             
http://bugs.php.net/fix.php?id=32207&r=submittedtwice
register_globals:            http://bugs.php.net/fix.php?id=32207&r=globals
PHP 3 support discontinued:  http://bugs.php.net/fix.php?id=32207&r=php3
Daylight Savings:            http://bugs.php.net/fix.php?id=32207&r=dst
IIS Stability:               http://bugs.php.net/fix.php?id=32207&r=isapi
Install GNU Sed:             http://bugs.php.net/fix.php?id=32207&r=gnused
Floating point limitations:  http://bugs.php.net/fix.php?id=32207&r=float
No Zend Extensions:          http://bugs.php.net/fix.php?id=32207&r=nozend
MySQL Configuration Error:   http://bugs.php.net/fix.php?id=32207&r=mysqlcfg

Reply via email to