Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5c74164

Browse files
Fix string coercion for $a .= $a (#11296)
free_op2_string may be set to false when the operands are not strings, and `result == op1 == op2`, by re-using the same string for both operands. In that case, the string should still be copied to result because result is not actually a string. Also change the op1 branch to stay consistent. Introduced by GH-10049
1 parent c230aa9 commit 5c74164

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

‎Zend/tests/bug79836_3.phpt‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--TEST--
2+
Bug #79836 ($a .= $a should coerce to string)
3+
--FILE--
4+
<?php
5+
$a = false;
6+
$a .= $a;
7+
var_dump($a);
8+
?>
9+
--EXPECT--
10+
string(0) ""

‎Zend/zend_operators.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2005,7 +2005,7 @@ ZEND_API zend_result ZEND_FASTCALL concat_function(zval *result, zval *op1, zval
20052005

20062006
has_op2_string:;
20072007
if (UNEXPECTED(ZSTR_LEN(op1_string) == 0)) {
2008-
if (EXPECTED(free_op2_string|| result != op2)) {
2008+
if (EXPECTED(result!=op2|| Z_TYPE_P(result) != IS_STRING)) {
20092009
if (result == orig_op1) {
20102010
i_zval_ptr_dtor(result);
20112011
}
@@ -2018,7 +2018,7 @@ has_op2_string:;
20182018
}
20192019
}
20202020
} else if (UNEXPECTED(ZSTR_LEN(op2_string) == 0)) {
2021-
if (EXPECTED(free_op1_string|| result != op1)) {
2021+
if (EXPECTED(result!=op1|| Z_TYPE_P(result) != IS_STRING)) {
20222022
if (result == orig_op1) {
20232023
i_zval_ptr_dtor(result);
20242024
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /