Bug #65254 [Com]: Exception not catchable when exception thrown in autoload with a namespace
| From: | ryan dot brothers at gmail dot com | Date: | Fri, 12 Jul 2013 18:48:34 +0000 |
| Subject: | Bug #65254 [Com]: Exception not catchable when exception thrown in autoload with a namespace | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-180237@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=65254&edit=1
ID: 65254
Comment by: ryan dot brothers at gmail dot com
Reported by: ryan dot brothers at gmail dot com
Summary: Exception not catchable when exception thrown in
autoload with a namespace
Status: Open
Type: Bug
Package: Scripting Engine problem
Operating System: Linux
PHP Version: 5.5.0
Block user comment: N
Private report: N
New Comment:
Upon further testing, I can reproduce the issue without using namespaces with the following:
<?php
function __autoload($class)
{
require('ns_test.php');
throw new \Exception('abcd');
}
try
{
test::go();
}
catch (Exception $e)
{
echo 'caught';
exit;
}
=================================================
ns_test.php:
<?php
class test
{
}
Previous Comments:
------------------------------------------------------------------------
[2013-07-12 18:41:12] ryan dot brothers at gmail dot com
Description:
------------
In the following code, the exception is not caught. In PHP 5.3, the exception is caught, but in PHP
5.4 and PHP 5.5, the exception is not caught. The issue only occurs when the class is in a
namespace. If I remove the namespace from the class, then the exception is caught.
Test script:
---------------
<?php
function __autoload($class)
{
require('ns_test.php');
throw new \Exception('abcd');
}
try
{
\ns_test\test::go();
}
catch (Exception $e)
{
echo 'caught';
exit;
}
=================================================
ns_test.php:
<?php
namespace ns_test;
class test
{
}
Expected result:
----------------
caught
Actual result:
--------------
Warning: Uncaught exception 'Exception' with message 'abcd' in /tmp/test.php:6
Stack trace:
#0 /tmp/test.php(11): __autoload('ns_test\test')
#1 {main}
thrown in /tmp/test.php on line 6
Fatal error: Call to undefined method ns_test\test::go() in /tmp/test.php on line 11
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=65254&edit=1