diff --git a/Zend/tests/bug63462.phpt b/Zend/tests/bug63462.phpt index 45c9507bbac58..f0a285548e39a 100644 --- a/Zend/tests/bug63462.phpt +++ b/Zend/tests/bug63462.phpt @@ -67,6 +67,5 @@ __isset publicProperty __isset protectedProperty __isset privateProperty __set nonExisting -__set publicProperty __set protectedProperty __set privateProperty diff --git a/Zend/tests/bug78226.phpt b/Zend/tests/bug78226.phpt new file mode 100644 index 0000000000000..fb83c7f4036b8 --- /dev/null +++ b/Zend/tests/bug78226.phpt @@ -0,0 +1,30 @@ +--TEST-- +Bug #78226: Unexpected __set behavior with typed properties +--FILE-- +prop2); + +$test->prop1 = 1; +$test->prop2 = 2; + +var_dump($test); + +?> +--EXPECT-- +object(Test)#1 (2) { + ["prop1"]=> + int(1) + ["prop2"]=> + int(2) +} diff --git a/Zend/zend_object_handlers.c b/Zend/zend_object_handlers.c index 65aefb6aec6c0..ca350bc84b6b3 100644 --- a/Zend/zend_object_handlers.c +++ b/Zend/zend_object_handlers.c @@ -819,23 +819,21 @@ ZEND_API zval *zend_std_write_property(zval *object, zval *member, zval *value, if (EXPECTED(IS_VALID_PROPERTY_OFFSET(property_offset))) { variable_ptr = OBJ_PROP(zobj, property_offset); - if (Z_TYPE_P(variable_ptr) != IS_UNDEF) { - Z_TRY_ADDREF_P(value); + Z_TRY_ADDREF_P(value); - if (UNEXPECTED(prop_info)) { - ZVAL_COPY_VALUE(&tmp, value); - if (UNEXPECTED(!zend_verify_property_type(prop_info, &tmp, EG(current_execute_data) && ZEND_CALL_USES_STRICT_TYPES(EG(current_execute_data))))) { - Z_TRY_DELREF_P(value); - variable_ptr = &EG(error_zval); - goto exit; - } - value = &tmp; + if (UNEXPECTED(prop_info)) { + ZVAL_COPY_VALUE(&tmp, value); + if (UNEXPECTED(!zend_verify_property_type(prop_info, &tmp, EG(current_execute_data) && ZEND_CALL_USES_STRICT_TYPES(EG(current_execute_data))))) { + Z_TRY_DELREF_P(value); + variable_ptr = &EG(error_zval); + goto exit; } + value = &tmp; + } found: - zend_assign_to_variable(variable_ptr, value, IS_TMP_VAR, EG(current_execute_data) && ZEND_CALL_USES_STRICT_TYPES(EG(current_execute_data))); - goto exit; - } + zend_assign_to_variable(variable_ptr, value, IS_TMP_VAR, EG(current_execute_data) && ZEND_CALL_USES_STRICT_TYPES(EG(current_execute_data))); + goto exit; } else if (EXPECTED(IS_DYNAMIC_PROPERTY_OFFSET(property_offset))) { if (EXPECTED(zobj->properties != NULL)) { if (UNEXPECTED(GC_REFCOUNT(zobj->properties) > 1)) { diff --git a/tests/classes/unset_properties.phpt b/tests/classes/unset_properties.phpt index 417542ddea91a..f403807a1983c 100644 --- a/tests/classes/unset_properties.phpt +++ b/tests/classes/unset_properties.phpt @@ -132,22 +132,22 @@ true __isset "publicProperty" __get "publicProperty" __get "publicProperty" -__set "publicProperty" to "new publicProperty value via setter" + new publicProperty value via setter -__set "publicProperty" to "new publicProperty value via public access" + true new publicProperty value via public access protectedProperty set __isset "protectedProperty"false __get "protectedProperty" -__set "protectedProperty" to "new protectedProperty value via setter" + __isset "protectedProperty"true new protectedProperty value via setter privateProperty set __isset "privateProperty"false __get "privateProperty" -__set "privateProperty" to "new privateProperty value via setter" + __isset "privateProperty"true new privateProperty value via setter