#32207 [Opn->Fbk]: Error triggered in wrong scope for include
ID: 32207
Updated by: sniper@php.net
Reported By: php-bug at zulan dot net
-Status: Open
+Status: Feedback
Bug Type: Zend Engine 2 problem
Operating System: Win32
PHP Version: 5.0.3
New Comment:
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
Previous Comments:
------------------------------------------------------------------------
[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
Thread (5 messages)