php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53036 class_exists fails to return for missing dependent classes
Submitted: 2010-10-10 17:53 UTC Modified: 2010-10-12 09:19 UTC
From: steven dot hartland at multiplay dot co dot uk Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.2.14 OS: FreeBSD 8.1-RELEASE
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: steven dot hartland at multiplay dot co dot uk
New email:
PHP Version: OS:

 

 [2010-10-10 17:53 UTC] 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'

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-10-12 07:55 UTC] aharvey@php.net
-Status: Open +Status: Bogus
 [2010-10-12 07:55 UTC] aharvey@php.net
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-12 09:19 UTC] steven dot hartland at multiplay dot co dot uk
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 15:01:28 2024 UTC