com php-src: Deprecate use of parent where no parent exists: Zend/tests/class_name_as_scalar_error_002.php t
Zend/tests/type_declarations/variance/parent_in_class .phpt Zend/zend_compile.c
| From: | Nikita Popov | Date: | Fri, 24 May 2019 08:58:46 +0000 |
| Subject: | com php-src: Deprecate use of parent where no parent exists: Zend/tests/class_name_as_scalar_error_002.php t Zend/tests/type_declarations/variance/parent_in_class .phpt Zend/zend_compile.c |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-106320@lists.php.net to get a copy of this message | ||
Commit: d7f3844c87c11073b717d0e888ab0d5c4074f216
Author: Nikita Popov <nikita.ppv@gmail.com> Fri, 24 May 2019 09:49:44 +0200
Parents: d9747c23a2e16825e141c5b2573afb805d42f97f
Branches: PHP-7.4 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=d7f3844c87c11073b717d0e888ab0d5c4074f216
Log:
Deprecate use of parent where no parent exists
This deprecation is part of the covariance RFC.
Changed paths:
M Zend/tests/class_name_as_scalar_error_002.phpt
M Zend/tests/type_declarations/variance/parent_in_class.phpt
M Zend/zend_compile.c
Diff:
diff --git a/Zend/tests/class_name_as_scalar_error_002.phpt
b/Zend/tests/class_name_as_scalar_error_002.phpt
index 3abba7f..cbea0c2 100644
--- a/Zend/tests/class_name_as_scalar_error_002.phpt
+++ b/Zend/tests/class_name_as_scalar_error_002.phpt
@@ -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}
diff --git a/Zend/tests/type_declarations/variance/parent_in_class.phpt
b/Zend/tests/type_declarations/variance/parent_in_class.phpt
index 88b711b..c651466 100644
--- a/Zend/tests/type_declarations/variance/parent_in_class.phpt
+++ b/Zend/tests/type_declarations/variance/parent_in_class.phpt
@@ -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
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index 43301b1..b66ac4d 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -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");
+ }
}
}
/* }}} */