From: Pedro Magalhães Date: Wed, 27 Sep 2017 00:31:03 +0000 (+0100) Subject: Fix #74922 - Try to resolve constants when importing trait properties X-Git-Tag: php-7.3.0alpha1~1099^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=897bdb42f084e20eaf8a4b88829fc94f72626fd0;p=php Fix #74922 - Try to resolve constants when importing trait properties --- diff --git a/NEWS b/NEWS index 35b828e359..d3ad412982 100644 --- a/NEWS +++ b/NEWS @@ -14,6 +14,8 @@ PHP NEWS (andrewnester) . Fixed bug #69954 (broken links and unused config items in distributed ini files). (petk) + . Fixed bug #74922 (Composed class has fatal error with duplicate, equal const + properties). (pmmaga) - BCMath: . Fixed bug #66364 (BCMath bcmul ignores scale parameter). (cmb) diff --git a/Zend/tests/traits/bug74922.phpt b/Zend/tests/traits/bug74922.phpt new file mode 100644 index 0000000000..16272b8f68 --- /dev/null +++ b/Zend/tests/traits/bug74922.phpt @@ -0,0 +1,16 @@ +--TEST-- +Bug #74922 (Composed class has fatal error with duplicate, equal const properties) +--FILE-- + +--EXPECT-- +DONE diff --git a/Zend/tests/traits/bug74922a.phpt b/Zend/tests/traits/bug74922a.phpt new file mode 100644 index 0000000000..40617bcdc8 --- /dev/null +++ b/Zend/tests/traits/bug74922a.phpt @@ -0,0 +1,16 @@ +--TEST-- +Bug #74922 (Composed class has fatal error with duplicate, equal const properties) +--FILE-- + +--EXPECT-- +DONE diff --git a/Zend/tests/traits/bug74922b.inc b/Zend/tests/traits/bug74922b.inc new file mode 100644 index 0000000000..b64ee21985 --- /dev/null +++ b/Zend/tests/traits/bug74922b.inc @@ -0,0 +1,9 @@ + +--EXPECT-- +DONE diff --git a/Zend/tests/traits/bug74922c.phpt b/Zend/tests/traits/bug74922c.phpt new file mode 100644 index 0000000000..367bbf4eab --- /dev/null +++ b/Zend/tests/traits/bug74922c.phpt @@ -0,0 +1,20 @@ +--TEST-- +Bug #74922 (Composed class has fatal error with duplicate, equal const properties) +--FILE-- +x); + +?> +--EXPECT-- +int(42) diff --git a/Zend/zend_inheritance.c b/Zend/zend_inheritance.c index a9c468493d..b9794b0d62 100644 --- a/Zend/zend_inheritance.c +++ b/Zend/zend_inheritance.c @@ -1584,19 +1584,32 @@ static void zend_do_traits_property_binding(zend_class_entry *ce) /* {{{ */ zend_hash_del(&ce->properties_info, prop_name); flags |= ZEND_ACC_CHANGED; } else { + not_compatible = 1; + if ((coliding_prop->flags & (ZEND_ACC_PPP_MASK | ZEND_ACC_STATIC)) == (flags & (ZEND_ACC_PPP_MASK | ZEND_ACC_STATIC))) { - /* flags are identical, now the value needs to be checked */ + /* the flags are identical, thus, the properties may be compatible */ + zval op1, op2; + if (flags & ZEND_ACC_STATIC) { - not_compatible = fast_is_not_identical_function(&ce->default_static_members_table[coliding_prop->offset], - &ce->traits[i]->default_static_members_table[property_info->offset]); + ZVAL_COPY_OR_DUP(&op1, &ce->default_static_members_table[coliding_prop->offset]); + ZVAL_COPY_OR_DUP(&op2, &ce->traits[i]->default_static_members_table[property_info->offset]); } else { - not_compatible = fast_is_not_identical_function(&ce->default_properties_table[OBJ_PROP_TO_NUM(coliding_prop->offset)], - &ce->traits[i]->default_properties_table[OBJ_PROP_TO_NUM(property_info->offset)]); + ZVAL_COPY_OR_DUP(&op1, &ce->default_properties_table[OBJ_PROP_TO_NUM(coliding_prop->offset)]); + ZVAL_COPY_OR_DUP(&op2, &ce->traits[i]->default_properties_table[OBJ_PROP_TO_NUM(property_info->offset)]); } - } else { - /* the flags are not identical, thus, we assume properties are not compatible */ - not_compatible = 1; + + /* if any of the values is a constant, we try to resolve it */ + if (UNEXPECTED(Z_TYPE(op1) == IS_CONSTANT_AST)) { + zval_update_constant_ex(&op1, ce); + } + if (UNEXPECTED(Z_TYPE(op2) == IS_CONSTANT_AST)) { + zval_update_constant_ex(&op2, ce); + } + + not_compatible = fast_is_not_identical_function(&op1, &op2); + zval_ptr_dtor_nogc(&op1); + zval_ptr_dtor_nogc(&op2); } if (not_compatible) {