com php-src: inheritance fixes: Zend/tests/type_declarations/ typed_properties_035.phpt Zend/zend_inheritance .c
| From: | Bob Weinand | Date: | Mon, 21 Mar 2016 20:38:24 +0000 |
| Subject: | com php-src: inheritance fixes: Zend/tests/type_declarations/ typed_properties_035.phpt Zend/zend_inheritance .c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-95659@lists.php.net to get a copy of this message | ||
Commit: bc450bb21bf30009b492f0eb43c55c867a63547c
Author: Joe Watkins <krakjoe@php.net> Mon, 21 Mar 2016 20:38:24 +0000
Parents: 3a057cbe9a32416a0bd84da50bfbe0e9b3020997
Branches: typed_ref_properties
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=bc450bb21bf30009b492f0eb43c55c867a63547c
Log:
inheritance fixes
Changed paths:
A Zend/tests/type_declarations/typed_properties_035.phpt
M Zend/zend_inheritance.c
Diff:
diff --git a/Zend/tests/type_declarations/typed_properties_035.phpt
b/Zend/tests/type_declarations/typed_properties_035.phpt
new file mode 100644
index 0000000..3ad55e2
--- /dev/null
+++ b/Zend/tests/type_declarations/typed_properties_035.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Test typed properties inheritance must not change type
+--FILE--
+<?php
+class Foo{
+ public $bar = 42;
+}
+
+class Baz extends Foo{
+ public int $bar = 33;
+}
+--EXPECTF--
+Fatal error: Type of Baz::$bar must not be defined (as in class Foo) in %s on line 8
+
diff --git a/Zend/zend_inheritance.c b/Zend/zend_inheritance.c
index bc11a0a..b034c8a 100644
--- a/Zend/zend_inheritance.c
+++ b/Zend/zend_inheritance.c
@@ -650,28 +650,6 @@ static void do_inherit_property(zend_property_info *parent_info, zend_string
*ke
if (UNEXPECTED(child)) {
child_info = Z_PTR_P(child);
-
- if (UNEXPECTED(parent_info->type && !(parent_info->flags & ZEND_ACC_PRIVATE)))
{
- if (parent_info->type == IS_OBJECT) {
- if (child_info->type != IS_OBJECT ||
- !zend_string_equals_ci(zend_resolve_property_type(parent_info->type_name,
parent_info->ce),
- zend_resolve_property_type(child_info->type_name, child_info->ce))) {
- zend_error_noreturn(E_COMPILE_ERROR,
- "Type of %s::$%s must be %s (as in class %s)",
- ZSTR_VAL(ce->name),
- ZSTR_VAL(key),
- ZSTR_VAL(zend_resolve_property_type(parent_info->type_name, parent_info->ce)),
- ZSTR_VAL(ce->parent->name));
- }
- } else if (parent_info->type != child_info->type) {
- zend_error_noreturn(E_COMPILE_ERROR,
- "Type of %s::$%s must be %s (as in class %s)",
- ZSTR_VAL(ce->name),
- ZSTR_VAL(key),
- zend_get_type_by_const(parent_info->type),
- ZSTR_VAL(ce->parent->name));
- }
- }
if (UNEXPECTED(parent_info->flags & (ZEND_ACC_PRIVATE|ZEND_ACC_SHADOW))) {
child_info->flags |= ZEND_ACC_CHANGED;
@@ -698,6 +676,36 @@ static void do_inherit_property(zend_property_info *parent_info, zend_string
*ke
child_info->offset = parent_info->offset;
}
}
+
+ if (!(child_info->flags & ZEND_ACC_CHANGED)) {
+ if (UNEXPECTED(parent_info->type && !(parent_info->flags & ZEND_ACC_PRIVATE)))
{
+ if (parent_info->type == IS_OBJECT) {
+ if (child_info->type != IS_OBJECT ||
+ !zend_string_equals_ci(zend_resolve_property_type(parent_info->type_name,
parent_info->ce),
+ zend_resolve_property_type(child_info->type_name, child_info->ce))) {
+ zend_error_noreturn(E_COMPILE_ERROR,
+ "Type of %s::$%s must be %s (as in class %s)",
+ ZSTR_VAL(ce->name),
+ ZSTR_VAL(key),
+ ZSTR_VAL(zend_resolve_property_type(parent_info->type_name, parent_info->ce)),
+ ZSTR_VAL(ce->parent->name));
+ }
+ } else if (parent_info->type != child_info->type) {
+ zend_error_noreturn(E_COMPILE_ERROR,
+ "Type of %s::$%s must be %s (as in class %s)",
+ ZSTR_VAL(ce->name),
+ ZSTR_VAL(key),
+ zend_get_type_by_const(parent_info->type),
+ ZSTR_VAL(ce->parent->name));
+ }
+ } else if (UNEXPECTED(child_info->type && !parent_info->type)) {
+ zend_error_noreturn(E_COMPILE_ERROR,
+ "Type of %s::$%s must not be defined (as in class %s)",
+ ZSTR_VAL(ce->name),
+ ZSTR_VAL(key),
+ ZSTR_VAL(ce->parent->name));
+ }
+ }
} else {
if (UNEXPECTED(parent_info->type && !(parent_info->flags & ZEND_ACC_PRIVATE)))
{
if (parent_info->type == IS_OBJECT) {