As we support constant array operands nowadays, the original check
didn't work anymore.
--- /dev/null
+--TEST--
+Array addition is not commutative -- do not swap operands
+--FILE--
+<?php
+
+$array = [1, 2, 3];
+$array = [4, 5, 6] + $array;
+var_dump($array);
+
+?>
+--EXPECT--
+array(3) {
+ [0]=>
+ int(4)
+ [1]=>
+ int(5)
+ [2]=>
+ int(6)
+}
zend_uchar tmp_type = opline->op1_type;
znode_op tmp = opline->op1;
- if (opline->opcode != ZEND_ADD || ZEND_OP1_TYPE(opline) == IS_CONST) {
+ if (opline->opcode != ZEND_ADD
+ || (ZEND_OP1_TYPE(opline) == IS_CONST
+ && Z_TYPE(ZEND_OP1_LITERAL(opline)) != IS_ARRAY)) {
/* protection from array add: $a = array + $a is not commutative! */
COPY_NODE(opline->op1, opline->op2);
COPY_NODE(opline->op2, tmp);