mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
Do not swap operands in array addition
As we support constant array operands nowadays, the original check didn't work anymore.
This commit is contained in:
parent
07b33992a2
commit
7dc5bc5063
2 changed files with 22 additions and 1 deletions
19
Zend/tests/array_addition_not_commutative.phpt
Normal file
19
Zend/tests/array_addition_not_commutative.phpt
Normal file
|
@ -0,0 +1,19 @@
|
|||
--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)
|
||||
}
|
|
@ -106,7 +106,9 @@ void zend_optimizer_pass3(zend_op_array *op_array)
|
|||
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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue