#50250 [Opn]: Exceptions can be thrown and caught in an autoload function
ID: 50250
Updated by: bjori@php.net
Reported By: brandon@php.net
Status: Open
-Bug Type: SPL related
+Bug Type: Scripting Engine problem
Operating System: Irrelevent
PHP Version: 5.3.1
New Comment:
This is also true for __autoload(), not only spl_register_autoload().
Bug or expected behavior as of PHP 5.3.0?
Previous Comments:
------------------------------------------------------------------------
[2009-11-20 19:50:03] brandon@php.net
Description:
------------
According to the PHP documentation, exceptions cannot be thrown inside
__autoload() functions, and prior to PHP 5.3, exceptions thrown resulted
in fatal errors. Since PHP 5.3, it has been possible to throw and catch
exceptions from __autoload() functions.
I'm happy to chalk this up to a documentation bug, and if it is I will
gladly fix it myself; however, I want to make sure this is intended
functionality and not an accidental inclusion that might be fixed in
future versions of PHP.
Reproduce code:
---------------
<?php
function autoload($class)
{
throw new Exception('test');
require $class . '.php';
}
spl_autoload_register('autoload');
try {
new NoExist();
}
catch (Exception $e)
{
echo 'unable to load the class.';
}
Expected result:
----------------
Fatal error, as the autoloader throws an exception which is not
allowed.
Actual result:
--------------
string of "unable to load the class."
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=50250&edit=1
Thread (6 messages)