Fix #75765 Exception on extend of undefined class
authortimurib <timok@ya.ru>
Sat, 6 Jan 2018 20:04:45 +0000 (23:04 +0300)
committerNikita Popov <nikita.ppv@gmail.com>
Fri, 12 Jan 2018 17:41:39 +0000 (18:41 +0100)
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
Zend/zend_compile.c
ext/spl/tests/bug73423.phpt
tests/classes/autoload_011.phpt
tests/classes/bug75765.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index e8fc786555db3f0f94edf50dd9e0bad43d433dd7..6dad61245a483f3cafc4ae370d5a82e77b3e258f 100644 (file)
--- 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)
index dbabfb36338bb4ada95bf60e4b990a2d996a5068..0beadace95ee15c12cfd2a1b4db805db9a53203d 100644 (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;
        }
 
index 58e1acb8220a8780f874809be43d1d81a1ff4f67..965b63318e1931ae8e2ea728d6394f082c564f8d 100644 (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
index aaea38c6f0ef0af6bd51561e85d2a1420d9f0b50..630cbf3208f3c08f4ba2ffdc7c2dbd9994cb9118 100644 (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
diff --git a/tests/classes/bug75765.phpt b/tests/classes/bug75765.phpt
new file mode 100644 (file)
index 0000000..d24f62d
--- /dev/null
@@ -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