Bug->Req #75765 [Opn]: Fatal error instead of Error exception when base class is not found

From: Date: Sat, 06 Jan 2018 20:07:58 +0000
Subject: Bug->Req #75765 [Opn]: Fatal error instead of Error exception when base class is not found
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-213399@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=75765&edit=1 ID: 75765 Updated by: nikic@php.net Reported by: contact at joycebabu dot com Summary: Fatal error instead of Error exception when base class is not found Status: Open -Type: Bug +Type: Feature/Change Request -Package: Dynamic loading +Package: Scripting Engine problem PHP Version: 7.2.1 Block user comment: N Private report: N New Comment: Supporting this would require larger changes to class binding, otherwise throwing would leave behind a partially-bound class. Previous Comments: ------------------------------------------------------------------------ [2018-01-06 19:59:18] timok at ya dot ru Issue is not related with autoloading. Same result occurs always when extending some undefined class regardless autoload settings: https://3v4l.org/Drv16 Also the "implements" statement behaves as well. The problem reproduced at least from 7.0 version (when most of fatal errors was replaced by Error exceptions). ------------------------------------------------------------------------ [2018-01-05 12:41:43] contact at joycebabu dot com 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 this bug report at https://bugs.php.net/bug.php?id=75765&edit=1

« previous php.bugs (#213399) next »