]> granicus.if.org Git - php/commitdiff
Deprecate use of parent where no parent exists
authorNikita Popov <nikita.ppv@gmail.com>
Fri, 24 May 2019 07:49:44 +0000 (09:49 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Fri, 24 May 2019 08:58:46 +0000 (10:58 +0200)
This deprecation is part of the covariance RFC.

Zend/tests/class_name_as_scalar_error_002.phpt
Zend/tests/type_declarations/variance/parent_in_class.phpt
Zend/zend_compile.c

index 3abba7f7fe589b0e9145aa40dd6bf9cf170c885c..cbea0c2dcca733b7e11ea5a1e0fca0d957aac46e 100644 (file)
@@ -11,6 +11,8 @@ namespace Foo\Bar {
 }
 ?>
 --EXPECTF--
+Deprecated: Cannot use "parent" when current class scope has no parent in %s on line %d
+
 Fatal error: Uncaught Error: Cannot use "parent" when current class scope has no parent in %s:%d
 Stack trace:
 #0 {main}
index 88b711bdddafc0e7f65d5e636e2c2143c33a3d45..c65146676dc8fc7557f1ba419eb66c583f2f3c74 100644 (file)
@@ -40,6 +40,8 @@ class B4 extends A4 {
 
 ?>
 --EXPECTF--
+Deprecated: Cannot use "parent" when current class scope has no parent in %s on line %d
+
 Warning: Declaration of B4::method(A4 $x) should be compatible with A4::method(P4 $x) in %s on line %d
 
 Warning: Could not check compatibility between B::method(A $x) and A::method(parent $x), because class parent is not available in %s on line %d
index 43301b11477cdc86d06aea2757567a6f0417b958..b66ac4dcba659854e025f2b0b6d759cae393545b 100644 (file)
@@ -1319,10 +1319,16 @@ static uint32_t zend_get_class_fetch_type_ast(zend_ast *name_ast) /* {{{ */
 
 static void zend_ensure_valid_class_fetch_type(uint32_t fetch_type) /* {{{ */
 {
-       if (fetch_type != ZEND_FETCH_CLASS_DEFAULT && !CG(active_class_entry) && zend_is_scope_known()) {
-               zend_error_noreturn(E_COMPILE_ERROR, "Cannot use \"%s\" when no class scope is active",
-                       fetch_type == ZEND_FETCH_CLASS_SELF ? "self" :
-                       fetch_type == ZEND_FETCH_CLASS_PARENT ? "parent" : "static");
+       if (fetch_type != ZEND_FETCH_CLASS_DEFAULT && zend_is_scope_known()) {
+               zend_class_entry *ce = CG(active_class_entry);
+               if (!ce) {
+                       zend_error_noreturn(E_COMPILE_ERROR, "Cannot use \"%s\" when no class scope is active",
+                               fetch_type == ZEND_FETCH_CLASS_SELF ? "self" :
+                               fetch_type == ZEND_FETCH_CLASS_PARENT ? "parent" : "static");
+               } else if (fetch_type == ZEND_FETCH_CLASS_PARENT && !ce->parent_name) {
+                       zend_error(E_DEPRECATED,
+                               "Cannot use \"parent\" when current class scope has no parent");
+               }
        }
 }
 /* }}} */