#50246 [Bgs]: Throw exception fails in __autoload() implementation
| From: | krzysztof dot talajko at gmail dot com | Date: | Fri, 20 Nov 2009 22:40:45 +0000 |
| Subject: | #50246 [Bgs]: Throw exception fails in __autoload() implementation | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-144894@lists.php.net to get a copy of this message | ||
ID: 50246
User updated by: krzysztof dot talajko at gmail dot com
Reported By: krzysztof dot talajko at gmail dot com
Status: Bogus
Bug Type: Scripting Engine problem
Operating System: Windows 7 RC
PHP Version: 5.2.11
New Comment:
Thank you for the Friendly Welcome.
My suggestion is to fix the manual in autoloading section, because it
is confusing. In php 5.3 exceptions can be thrown without this error.
There is no information about this difference between various php
versions. Second confusing thing is that in Zend Framework there is also
exception thrown in autoload function ... but I assume that some of ZF
programmers just didn't read the manual.
Previous Comments:
------------------------------------------------------------------------
[2009-11-20 17:56:20] jani@php.net
Thank you for not reading the manual or searching existing bug reports.
RTFM: http://php.net/autoload
------------------------------------------------------------------------
[2009-11-20 16:05:47] krzysztof dot talajko at gmail dot com
Simpler reproduce code is (results same as in original code):
<?php
function __autoload($class) {
throw new Exception("Class ".$class." not found");
}
try{
new Foo;
}
catch (Exception $e) {
echo "Caught load class failed exception (".$e->getMessage().").";
}
------------------------------------------------------------------------
[2009-11-20 15:58:12] krzysztof dot talajko at gmail dot com
Description:
------------
Throw exception in __autoload() implementation is impossible. Instead
fatal error "Class (...) not found" is reported.
Reproduce code:
---------------
<?php
function loader($class) {
@include_once($class.'.php');
if (!class_exists($class, false)) {
throw new Exception("Class ".$class." not found");
}
}
spl_autoload_register('loader');
try{
class FooClass extends Some_Not_Existing_Class {}
}
catch (Exception $e) {
echo "Caught load class failed exception (".$e->getMessage().").";
}
Expected result:
----------------
Caught load class failed exception (Class Some_Not_Existing_Class not
found).
Actual result:
--------------
Fatal error: Class 'Some_Not_Existing_Class' not found in
C:\dev\workspace\foo.php on line 19
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=50246&edit=1