Edit report at http://bugs.php.net/bug.php?id=53036&edit=1
ID: 53036
User updated by: steven dot hartland at multiplay dot co dot uk
Reported by: steven dot hartland at multiplay dot co dot uk
Summary: class_exists fails to return for missing dependent
classes
Status: Bogus
Type: Bug
Package: Class/Object related
Operating System: FreeBSD 8.1-RELEASE
PHP Version: 5.2.14
Block user comment: N
New Comment:
But the whole idea of using this type of autoloader is that they can be
chained
so
you need to ensure that each individual handler doesn't throw an error
directly,
which is why @ is used.
The handler here has no idea if another handler will successfully load
the
class,
so it has to suppress the error from include_once.
In addition the class_exists man page makes no mention of it throwing a
fatal
error if the class cannot be found via autoload, so based on this even
though it
failed to autoload the class the expected behaviour should simply be a
return of
false.
Previous Comments:
------------------------------------------------------------------------
[2010-10-12 07:55:41] [email protected]
You're suppressing errors with the @ operator in the include_once call
-- because there's no MyBaseClass.php file, the autoload fails, which
results in a fatal error when class MyBaseClass can't be found. Without
the @ operator, you get two warnings, then the fatal error, which is
silenced in your code.
Not a PHP bug -> closing.
------------------------------------------------------------------------
[2010-10-10 17:53:04] steven dot hartland at multiplay dot co dot uk
Description:
------------
If you call class_exists( $sClass ) which in turn triggers an autoloader
that
fails to load a dependent class of $sClass e.g. where $sClass extends a
missing
class, then class_exists fails silently and never returns.
Note this only fails on missing dependent classes if the original class
fails to
load then class_exists returns false as expected.
Also tested on 5.3.3 same results
Test script:
---------------
Test case files here:
http://www.multiplaygameservers.com/dropzone/php-autoload-failure.tar.gz
Expected result:
----------------
factory: MyClass
autoload: MyClass
including: MyClass
autoload: MyBaseClass
including: MyBaseClass
included: for MyBaseClass,
Failed to autoload: MyClass
Failed to load 'MyClass'
Actual result:
--------------
factory: MyClass
autoload: MyClass
including: MyClass
autoload: MyBaseClass
including: MyBaseClass
included: for MyBaseClass,
<-- Nothing more -->
Running with missing initial class:
factory: MyClass
autoload: MyClass
including: MyClass
included: for MyClass,
Failed to autoload: MyClass
Failed to load 'MyClass'
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=53036&edit=1