Skip to content

Commit c5745f4

Browse files
committed
Fix array to string conversion warning emitted in optimizer
Fixes GH-16408 Closes GH-16380
1 parent 34e635f commit c5745f4

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ PHP NEWS
3434
. Fixed bug GH-16361 (mb_substr overflow on start/length arguments).
3535
(David Carlier)
3636

37+
- Opcache:
38+
. Fixed bug GH-16408 (Array to string conversion warning emitted in
39+
optimizer). (ilutov)
40+
3741
- OpenSSL:
3842
. Fixed bug GH-16357 (openssl may modify member types of certificate arrays).
3943
(cmb)

Zend/Optimizer/pass1.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@
3434
#include "zend_execute.h"
3535
#include "zend_vm.h"
3636

37+
#define TO_STRING_NOWARN(val) do { \
38+
if (Z_TYPE_P(val) < IS_ARRAY) { \
39+
convert_to_string(val); \
40+
} \
41+
} while (0)
42+
3743
static void replace_by_const_or_qm_assign(zend_op_array *op_array, zend_op *opline, zval *result) {
3844
if (opline->op1_type == IS_CONST) {
3945
literal_dtor(&ZEND_OP1_LITERAL(opline));
@@ -64,10 +70,10 @@ void zend_optimizer_pass1(zend_op_array *op_array, zend_optimizer_ctx *ctx)
6470
case ZEND_CONCAT:
6571
case ZEND_FAST_CONCAT:
6672
if (opline->op1_type == IS_CONST && Z_TYPE(ZEND_OP1_LITERAL(opline)) != IS_STRING) {
67-
convert_to_string(&ZEND_OP1_LITERAL(opline));
73+
TO_STRING_NOWARN(&ZEND_OP1_LITERAL(opline));
6874
}
6975
if (opline->op2_type == IS_CONST && Z_TYPE(ZEND_OP2_LITERAL(opline)) != IS_STRING) {
70-
convert_to_string(&ZEND_OP2_LITERAL(opline));
76+
TO_STRING_NOWARN(&ZEND_OP2_LITERAL(opline));
7177
}
7278
ZEND_FALLTHROUGH;
7379
case ZEND_ADD:
@@ -100,7 +106,7 @@ void zend_optimizer_pass1(zend_op_array *op_array, zend_optimizer_ctx *ctx)
100106
case ZEND_ASSIGN_OP:
101107
if (opline->extended_value == ZEND_CONCAT && opline->op2_type == IS_CONST
102108
&& Z_TYPE(ZEND_OP2_LITERAL(opline)) != IS_STRING) {
103-
convert_to_string(&ZEND_OP2_LITERAL(opline));
109+
TO_STRING_NOWARN(&ZEND_OP2_LITERAL(opline));
104110
}
105111
break;
106112

Zend/tests/gh16408.phpt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
GH-16408: Array to string conversion warning emitted in optimizer
3+
--FILE--
4+
<?php
5+
$counter = 0;
6+
ob_start(function ($buffer) use (&$c, &$counter) {
7+
$c = 0;
8+
++$counter;
9+
}, 1);
10+
$c .= [];
11+
$c .= [];
12+
ob_end_clean();
13+
echo $counter . "\n";
14+
?>
15+
--EXPECT--
16+
3

0 commit comments

Comments
 (0)