Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions Zend/Optimizer/pass1.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
#include "zend_execute.h"
#include "zend_vm.h"

#define TO_STRING_NOWARN(val) do { \
if (Z_TYPE_P(val) < IS_ARRAY) { \
convert_to_string(val); \
} \
} while (0)

static void replace_by_const_or_qm_assign(zend_op_array *op_array, zend_op *opline, zval *result) {
if (opline->op1_type == IS_CONST) {
literal_dtor(&ZEND_OP1_LITERAL(opline));
Expand Down Expand Up @@ -64,10 +70,10 @@ void zend_optimizer_pass1(zend_op_array *op_array, zend_optimizer_ctx *ctx)
case ZEND_CONCAT:
case ZEND_FAST_CONCAT:
if (opline->op1_type == IS_CONST && Z_TYPE(ZEND_OP1_LITERAL(opline)) != IS_STRING) {
convert_to_string(&ZEND_OP1_LITERAL(opline));
TO_STRING_NOWARN(&ZEND_OP1_LITERAL(opline));
}
if (opline->op2_type == IS_CONST && Z_TYPE(ZEND_OP2_LITERAL(opline)) != IS_STRING) {
convert_to_string(&ZEND_OP2_LITERAL(opline));
TO_STRING_NOWARN(&ZEND_OP2_LITERAL(opline));
}
ZEND_FALLTHROUGH;
case ZEND_ADD:
Expand Down Expand Up @@ -100,7 +106,7 @@ void zend_optimizer_pass1(zend_op_array *op_array, zend_optimizer_ctx *ctx)
case ZEND_ASSIGN_OP:
if (opline->extended_value == ZEND_CONCAT && opline->op2_type == IS_CONST
&& Z_TYPE(ZEND_OP2_LITERAL(opline)) != IS_STRING) {
convert_to_string(&ZEND_OP2_LITERAL(opline));
TO_STRING_NOWARN(&ZEND_OP2_LITERAL(opline));
}
break;

Expand Down
16 changes: 16 additions & 0 deletions Zend/tests/gh16408.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
--TEST--
GH-16408: Warning emitted during array to string conversion in optimizer
--FILE--
<?php
$counter = 0;
ob_start(function ($buffer) use (&$c, &$counter) {
$c = 0;
++$counter;
}, 1);
$c .= [];
$c .= [];
ob_end_clean();
echo $counter . "\n";
?>
--EXPECT--
3