#32207 [Com]: Error triggered in wrong scope for include
| From: | jowag89 at gmx dot ch | Date: | Sun, 06 Mar 2005 18:56:18 +0000 |
| Subject: | #32207 [Com]: Error triggered in wrong scope for include | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-74941@lists.php.net to get a copy of this message | ||
ID: 32207
Comment by: jowag89 at gmx dot ch
Reported By: php-bug at zulan dot net
Status: Feedback
Bug Type: Zend Engine 2 problem
Operating System: Win32
PHP Version: 5.0.3
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2005-03-06 19:19:31] 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:13:55] 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.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=32207&edit=1