Bug #75765 [NEW]: Fatal error instead of Error exception when base class is not found

From: Date: Fri, 05 Jan 2018 12:41:45 +0000
Subject: Bug #75765 [NEW]: Fatal error instead of Error exception when base class is not found
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-213385@lists.php.net to get a copy of this message
From: contact at joycebabu dot com Operating system: PHP version: 7.2.1 Package: Dynamic loading Bug Type: Bug Bug description:Fatal error instead of Error exception when base class is not found Description: ------------ When the base class of a dynamically loaded class is not found, PHP raises a fatal error instead of throwing an exception. Test script: --------------- <?php spl_autoload_register(function ($class_name) { if (file_exists(__DIR__ . "/{$class_name}.php")) { include __DIR__ . "/{$class_name}.php"; } }); // Following code throws an exception since CDE is not found try { $a = new CDE(); } catch (\Throwable $e) { echo 'CAUGHT CDE', PHP_EOL; } /* * Create ABC.php with an empty class ABC extending base class CDE * <?php class ABC extends CDE {} */ // Following code raises a fatal error since CDE (base class of ABC) is not found try { $a = new ABC(); } catch (\Throwable $e) { echo 'CAUGHT CDE', PHP_EOL; } Expected result: ---------------- CAUGHT CDE CAUGHT CDE Actual result: -------------- CAUGHT CDE PHP Fatal error: Class 'CDE' not found in /path/to/file/ABC.php on line 3 Fatal error: Class 'CDE' not found in /path/to/file/ABC.php on line 3 -- Edit bug report at https://bugs.php.net/bug.php?id=75765&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=75765&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=75765&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=75765&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=75765&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=75765&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=75765&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=75765&r=needscript Try newer version: https://bugs.php.net/fix.php?id=75765&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=75765&r=support Expected behavior: https://bugs.php.net/fix.php?id=75765&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=75765&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=75765&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=75765&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=75765&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=75765&r=dst IIS Stability: https://bugs.php.net/fix.php?id=75765&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=75765&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=75765&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=75765&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=75765&r=mysqlcfg

« previous php.bugs (#213385) next »