Bug #79022 [NEW]: class_exists returns True for classes that are not ready to be used

From: Date: Mon, 23 Dec 2019 22:24:13 +0000
Subject: Bug #79022 [NEW]: class_exists returns True for classes that are not ready to be used
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-224500@lists.php.net to get a copy of this message
From: mech at themech dot net Operating system: Linux PHP version: 7.4.1 Package: *General Issues Bug Type: Bug Bug description:class_exists returns True for classes that are not ready to be used Description: ------------ I noticed this issue while debugging Koseven framework with PHP 7.4. It is related to class autoloading. Imagine there is an autoloader function registered with the following code inside: if (class_exists('B', False)) { new B(); } If class B extends some other class A and autoloading function is called to load class A then class_exists('B', false) returns true even if B is not "fully loaded" as its parent class A is still to be loaded. So under PHP 7.4 the "new B()" is being executed and throws "Fatal error: Uncaught Error: Class 'B' not found". The same code works with PHP 7.3 Test script: --------------- <?php // classes/Foo.php: class Foo extends Bar {} // classes/Bar.php: class Bar {} function my_autoloader($class) { if (class_exists('Foo', False)) { new Foo(); } if ($class == 'Foo' or $class == 'Bar') { include "classes/$class.php"; } } spl_autoload_register('my_autoloader'); new Foo(); echo "end" Expected result: ---------------- class_exists should not return true for the class that does not exist yet.atal Actual result: -------------- Fatal error, class not found. -- Edit bug report at https://bugs.php.net/bug.php?id=79022&edit=1 -- Fix committed: https://bugs.php.net/fix.php?id=79022&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=79022&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=79022&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=79022&r=needscript Try newer version: https://bugs.php.net/fix.php?id=79022&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=79022&r=support Expected behavior: https://bugs.php.net/fix.php?id=79022&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=79022&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=79022&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=79022&r=globals PHP version support discontinued: https://bugs.php.net/fix.php?id=79022&r=phptooold Daylight Savings: https://bugs.php.net/fix.php?id=79022&r=dst IIS Stability: https://bugs.php.net/fix.php?id=79022&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=79022&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=79022&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=79022&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=79022&r=mysqlcfg

« previous php.bugs (#224500) next »