Req #75765 [Opn->Csd]: Fatal error instead of Error exception when base class is not found
| From: | nikic@php.net | Date: | Fri, 12 Jan 2018 17:44:26 +0000 |
| Subject: | Req #75765 [Opn->Csd]: 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-213504@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
+Status: Closed
Type: Feature/Change Request
Package: Scripting Engine problem
PHP Version: 7.2.1
Block user comment: N
Private report: N
New Comment:
Automatic comment on behalf of timok@ya.ru
Revision: http://git.php.net/?p=php-src.git;a=commit;h=a484b9a5359bd8252234c3965a6fb7f1a1a98b4a
Log: Fix #75765 Exception on extend of undefined class
Previous Comments:
------------------------------------------------------------------------
[2018-01-06 20:07:57] nikic@php.net
Supporting this would require larger changes to class binding, otherwise throwing would leave behind
a partially-bound class.
------------------------------------------------------------------------
[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