php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65254 Exception not catchable when exception thrown in autoload with a namespace
Submitted: 2013-07-12 18:41 UTC Modified: 2013-07-14 03:36 UTC
From: ryan dot brothers at gmail dot com Assigned: laruence (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.5.0 OS: Linux
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: ryan dot brothers at gmail dot com
New email:
PHP Version: OS:

 

 [2013-07-12 18:41 UTC] 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


Patches

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-07-12 18:48 UTC] ryan dot brothers at gmail dot com
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
{

}
 [2013-07-14 03:36 UTC] laruence@php.net
-Assigned To: +Assigned To: laruence
 [2013-07-14 04:02 UTC] laruence@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src.git;a=commit;h=ebad5178c4ae0da124469b1432fb0e890f6147da
Log: Fixed bug #65254 (Exception not catchable when exception thrown in autoload with a namespace).
 [2013-07-14 04:02 UTC] laruence@php.net
-Status: Assigned +Status: Closed
 [2014-10-07 23:18 UTC] stas@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=ebad5178c4ae0da124469b1432fb0e890f6147da
Log: Fixed bug #65254 (Exception not catchable when exception thrown in autoload with a namespace).
 [2014-10-07 23:29 UTC] stas@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=ebad5178c4ae0da124469b1432fb0e890f6147da
Log: Fixed bug #65254 (Exception not catchable when exception thrown in autoload with a namespace).
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Mon Oct 21 04:01:26 2019 UTC