From a484b9a5359bd8252234c3965a6fb7f1a1a98b4a Mon Sep 17 00:00:00 2001 From: timurib Date: Sat, 6 Jan 2018 23:04:45 +0300 Subject: [PATCH] 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. --- NEWS | 2 ++ Zend/zend_compile.c | 2 +- ext/spl/tests/bug73423.phpt | 13 ++++++++++++- tests/classes/autoload_011.phpt | 5 ++++- tests/classes/bug75765.phpt | 22 ++++++++++++++++++++++ 5 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 tests/classes/bug75765.phpt diff --git a/NEWS b/NEWS index e8fc786555..6dad61245a 100644 --- a/NEWS +++ b/NEWS @@ -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) diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index dbabfb3633..0beadace95 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -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; } diff --git a/ext/spl/tests/bug73423.phpt b/ext/spl/tests/bug73423.phpt index 58e1acb822..965b63318e 100644 --- a/ext/spl/tests/bug73423.phpt +++ b/ext/spl/tests/bug73423.phpt @@ -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 diff --git a/tests/classes/autoload_011.phpt b/tests/classes/autoload_011.phpt index aaea38c6f0..630cbf3208 100644 --- a/tests/classes/autoload_011.phpt +++ b/tests/classes/autoload_011.phpt @@ -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 diff --git a/tests/classes/bug75765.phpt b/tests/classes/bug75765.phpt new file mode 100644 index 0000000000..d24f62db80 --- /dev/null +++ b/tests/classes/bug75765.phpt @@ -0,0 +1,22 @@ +--TEST-- +Ensure that extending of undefined class throws the exception +--FILE-- + +--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 -- 2.50.1