diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index 717934fc760..1b0dd4f232a 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -1396,6 +1396,13 @@ static zend_never_inline void zend_binary_assign_op_typed_ref(zend_reference *re { zval z_copy; + /* Make sure that in-place concatenation is used if the LHS is a string. */ + if (opline->extended_value == ZEND_CONCAT && Z_TYPE(ref->val) == IS_STRING) { + concat_function(&ref->val, &ref->val, value); + ZEND_ASSERT(Z_TYPE(ref->val) == IS_STRING && "Concat should return string"); + return; + } + zend_binary_op(&z_copy, &ref->val, value OPLINE_CC); if (EXPECTED(zend_verify_ref_assignable_zval(ref, &z_copy, EX_USES_STRICT_TYPES()))) { zval_ptr_dtor(&ref->val); @@ -1409,6 +1416,13 @@ static zend_never_inline void zend_binary_assign_op_typed_prop(zend_property_inf { zval z_copy; + /* Make sure that in-place concatenation is used if the LHS is a string. */ + if (opline->extended_value == ZEND_CONCAT && Z_TYPE_P(zptr) == IS_STRING) { + concat_function(zptr, zptr, value); + ZEND_ASSERT(Z_TYPE_P(zptr) == IS_STRING && "Concat should return string"); + return; + } + zend_binary_op(&z_copy, zptr, value OPLINE_CC); if (EXPECTED(zend_verify_property_type(prop_info, &z_copy, EX_USES_STRICT_TYPES()))) { zval_ptr_dtor(zptr);