Fix #75765 Exception on extend of undefined class

As the parent class is fetched prior to binding, there are no
safety concerns in this case and we can replace the fatal error
with an Error exception.
This commit is contained in:
timurib 2018-01-06 23:04:45 +03:00 committed by Nikita Popov
parent 2d083a3da7
commit a484b9a535
5 changed files with 41 additions and 3 deletions

2
NEWS
View File

@ -31,6 +31,8 @@ PHP NEWS
(Nikita)
. Fixed bug #73108 (Internal class cast handler uses integer instead of
float). (Nikita)
. Fixed bug #75765 (Fatal error instead of Error exception when base class is
not found). (Timur Ibragimov)
- BCMath:
. Fixed bug #66364 (BCMath bcmul ignores scale parameter). (cmb)

View File

@ -6387,7 +6387,7 @@ void zend_compile_class_decl(zend_ast *ast) /* {{{ */
"Cannot use '%s' as class name as it is reserved", ZSTR_VAL(extends_name));
}
zend_compile_class_ref(&extends_node, extends_ast, 0);
zend_compile_class_ref(&extends_node, extends_ast, 1);
ce->ce_flags |= ZEND_ACC_INHERITED;
}

View File

@ -68,4 +68,15 @@ foreach (new \RecursiveIteratorIterator (new fooIterator ($foo)) as $bar) ;
?>
--EXPECTF--
Fatal error: Class 'NotExists' not found in %sbug73423.php(%d) : eval()'d code on line 1
Fatal error: Uncaught Error: Class 'NotExists' not found in %sbug73423.php(%d) : eval()'d code:1
Stack trace:
#0 %sbug73423.php(%d): eval()
#1 %sbug73423.php(%d): fooIterator->__destruct()
#2 {main}
Next Error: Class 'NotExists' not found in %sbug73423.php(%d) : eval()'d code:1
Stack trace:
#0 %sbug73423.php(%d): eval()
#1 %sbug73423.php(%d): fooIterator->__destruct()
#2 {main}
thrown in %sbug73423.php(%d) : eval()'d code on line 1

View File

@ -14,4 +14,7 @@ class C extends UndefBase
--EXPECTF--
In autoload: string(9) "UndefBase"
Fatal error: Class 'UndefBase' not found in %s on line %d
Fatal error: Uncaught Error: Class 'UndefBase' not found in %s:%d
Stack trace:
#0 {main}
thrown in %sautoload_011.php on line %d

View File

@ -0,0 +1,22 @@
--TEST--
Ensure that extending of undefined class throws the exception
--FILE--
<?php
try {
class A extends B {}
} catch (Error $e) {
var_dump(class_exists('A'));
var_dump(class_exists('B'));
throw $e;
}
?>
--EXPECTF--
bool(false)
bool(false)
Fatal error: Uncaught Error: Class 'B' not found in %sbug75765.php:%d
Stack trace:
#0 {main}
thrown in %sbug75765.php on line %d