diff --git a/Zend/tests/bug60536_001.phpt b/Zend/tests/bug60536_001.phpt new file mode 100644 index 00000000000..5a7008e3938 --- /dev/null +++ b/Zend/tests/bug60536_001.phpt @@ -0,0 +1,26 @@ +--TEST-- +Bug #60536 (Traits Segfault) +--FILE-- +x; + } +} +class Z extends Y { + function z() { + return ++$this->x; + } +} +$a = new Z(); +$a->x(); +echo "DONE"; +?> +--EXPECTF-- +Strict Standards: X and T define the same property ($x) in the composition of Y. This might be incompatible, to improve maintainability consider using accessor methods in traits instead. Class was composed in %sbug60536_001.php on line %d +DONE diff --git a/Zend/tests/bug60536_002.phpt b/Zend/tests/bug60536_002.phpt new file mode 100644 index 00000000000..0bca98382e7 --- /dev/null +++ b/Zend/tests/bug60536_002.phpt @@ -0,0 +1,40 @@ +--TEST-- +The same rules are applied for properties that are defined in the class hierarchy. Thus, if the properties are compatible, a notice is issued, if not a fatal error occures. (relevant with #60536) +--FILE-- +hello = "foo"; +?> +--EXPECTF-- +PRE-CLASS-GUARD + +Strict Standards: Notice and THello1 define the same property ($hello) in the composition of Notice. This might be incompatible, to improve maintainability consider using accessor methods in traits instead. Class was composed in %s on line %d +POST-CLASS-GUARD + +Fatal error: TraitsTest and THello1 define the same property ($hello) in the composition of TraitsTest. However, the definition differs and is considered incompatible. Class was composed in %s on line %d diff --git a/Zend/tests/bug60536_003.phpt b/Zend/tests/bug60536_003.phpt new file mode 100644 index 00000000000..8ddca352af2 --- /dev/null +++ b/Zend/tests/bug60536_003.phpt @@ -0,0 +1,49 @@ +--TEST-- +Private (relevant to #60536) +--FILE-- + +--EXPECTF-- +Strict Standards: BaseWithPropA and AHelloProperty define the same property ($hello) in the composition of SubclassA. This might be incompatible, to improve maintainability consider using accessor methods in traits instead. Class was composed in %sbug60536_003.php on line %d + +Strict Standards: BaseWithTPropB and AHelloProperty define the same property ($hello) in the composition of SubclassB. This might be incompatible, to improve maintainability consider using accessor methods in traits instead. Class was composed in %sbug60536_003.php on line %d +object(SubclassA)#%d (2) { + ["hello":"SubclassA":private]=> + int(0) + ["hello":"BaseWithPropA":private]=> + int(0) +} +object(SubclassB)#%d (2) { + ["hello":"SubclassB":private]=> + int(0) + ["hello":"BaseWithTPropB":private]=> + int(0) +} diff --git a/Zend/tests/bug60536_004.phpt b/Zend/tests/bug60536_004.phpt new file mode 100644 index 00000000000..4ae326ef7c9 --- /dev/null +++ b/Zend/tests/bug60536_004.phpt @@ -0,0 +1,39 @@ +--TEST-- +Introducing new private variables of the same name in a subclass is ok, and does not lead to any output. That is consitent with normal inheritance handling. (relevant to #60536) +--FILE-- + +--EXPECTF-- +PRE-CLASS-GUARD + +Strict Standards: Base and THello1 define the same property ($hello) in the composition of SameNameInSubClassNoNotice. This might be incompatible, to improve maintainability consider using accessor methods in traits instead. Class was composed in %sbug60536_004.php on line %d +POST-CLASS-GUARD + +Strict Standards: Notice and THello1 define the same property ($hello) in the composition of Notice. This might be incompatible, to improve maintainability consider using accessor methods in traits instead. Class was composed in %sbug60536_004.php on line %d +POST-CLASS-GUARD2 diff --git a/Zend/tests/bug60536_005.phpt b/Zend/tests/bug60536_005.phpt new file mode 100644 index 00000000000..378adcc9c03 --- /dev/null +++ b/Zend/tests/bug60536_005.phpt @@ -0,0 +1,38 @@ +--TEST-- +Introducing new private variables of the same name in a subclass is ok, and does not lead to any output. That is consitent with normal inheritance handling. (relevant to #60536) +--FILE-- + +--EXPECTF-- +PRE-CLASS-GUARD + +Strict Standards: Base and THello1 define the same property ($hello) in the composition of SameNameInSubClassProducesNotice. This might be incompatible, to improve maintainability consider using accessor methods in traits instead. Class was composed in %s on line %d +POST-CLASS-GUARD + +Strict Standards: Notice and THello1 define the same property ($hello) in the composition of Notice. This might be incompatible, to improve maintainability consider using accessor methods in traits instead. Class was composed in %s on line %d +POST-CLASS-GUARD2 diff --git a/Zend/zend_object_handlers.c b/Zend/zend_object_handlers.c index b43021dd229..be04bf3565e 100644 --- a/Zend/zend_object_handlers.c +++ b/Zend/zend_object_handlers.c @@ -62,6 +62,7 @@ ZEND_API void rebuild_object_properties(zend_object *zobj) /* {{{ */ ALLOC_HASHTABLE(zobj->properties); zend_hash_init(zobj->properties, 0, NULL, ZVAL_PTR_DTOR, 0); if (ce->default_properties_count) { + int *flags = ecalloc(ce->default_properties_count, sizeof(int)); for (zend_hash_internal_pointer_reset_ex(&ce->properties_info, &pos); zend_hash_get_current_data_ex(&ce->properties_info, (void**)&prop_info, &pos) == SUCCESS; zend_hash_move_forward_ex(&ce->properties_info, &pos)) { @@ -70,6 +71,7 @@ ZEND_API void rebuild_object_properties(zend_object *zobj) /* {{{ */ prop_info->offset >= 0 && zobj->properties_table[prop_info->offset]) { zend_hash_quick_add(zobj->properties, prop_info->name, prop_info->name_length+1, prop_info->h, (void**)&zobj->properties_table[prop_info->offset], sizeof(zval*), (void**)&zobj->properties_table[prop_info->offset]); + flags[prop_info->offset] = 1; } } while (ce->parent && ce->parent->default_properties_count) { @@ -81,11 +83,16 @@ ZEND_API void rebuild_object_properties(zend_object *zobj) /* {{{ */ (prop_info->flags & ZEND_ACC_STATIC) == 0 && (prop_info->flags & ZEND_ACC_PRIVATE) != 0 && prop_info->offset >= 0 && - zobj->properties_table[prop_info->offset]) { - zend_hash_quick_add(zobj->properties, prop_info->name, prop_info->name_length+1, prop_info->h, (void**)&zobj->properties_table[prop_info->offset], sizeof(zval*), (void**)&zobj->properties_table[prop_info->offset]); + zobj->properties_table[prop_info->offset]) { + if (UNEXPECTED(flags[prop_info->offset])) { + zend_hash_quick_add(zobj->properties, prop_info->name, prop_info->name_length+1, prop_info->h, (void**)zobj->properties_table[prop_info->offset], sizeof(zval*), (void**)&zobj->properties_table[prop_info->offset]); + } else { + zend_hash_quick_add(zobj->properties, prop_info->name, prop_info->name_length+1, prop_info->h, (void**)&zobj->properties_table[prop_info->offset], sizeof(zval*), (void**)&zobj->properties_table[prop_info->offset]); + } } } } + efree(flags); } } }