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

From: Date: Sat, 06 Jan 2018 19:59:20 +0000
Subject: Bug #75765 [Com]: 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-213398@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
 Comment by:         timok at ya dot ru
 Reported by:        contact at joycebabu dot com
 Summary:            Fatal error instead of Error exception when base
                     class is not found
 Status:             Open
 Type:               Bug
 Package:            Dynamic loading
 PHP Version:        7.2.1
 Block user comment: N
 Private report:     N

 New Comment:

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).


Previous Comments:
------------------------------------------------------------------------
[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


Thread (4 messages)

« previous php.bugs (#213398) next »