php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #32207 Error triggered in wrong scope for include
Submitted: 2005-03-06 19:13 UTC Modified: 2005-03-21 23:48 UTC
Votes:3
Avg. Score:4.7 ± 0.5
Reproduced:3 of 3 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: php-bug at zulan dot net Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5CVS-2005-03-06 OS: Win32
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: php-bug at zulan dot net
New email:
PHP Version: OS:

 

 [2005-03-06 19:13 UTC] php-bug at zulan dot net
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.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-03-06 19:19 UTC] sniper@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5-win32-latest.zip


 [2005-03-06 19:56 UTC] jowag89 at gmx dot ch
Here's the result of running it on my Linux-Box.
php version: php5-200503061730
Catched exception outside of
test():
test(missing_file.php): failed to open stream: No such file or directory
Catched exception inside of
test():
fopen() expects at least 2 parameters, 1 given

Looks like the problem is still there in the cvs version.
 [2005-03-21 23:48 UTC] sniper@php.net
Works fine for me.

 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 17 14:04:04 2025 UTC