@@ -6814,6 +6814,16 @@ ZEND_API zend_bool zend_binary_op_produces_numeric_string_error(uint32_t opcode,
6814
6814
}
6815
6815
/* }}} */
6816
6816
6817
+ ZEND_API zend_bool zend_binary_op_produces_array_conversion_error (uint32_t opcode , zval * op1 , zval * op2 ) /* {{{ */
6818
+ {
6819
+ if (opcode == ZEND_CONCAT && (Z_TYPE_P (op1 ) == IS_ARRAY || Z_TYPE_P (op2 ) == IS_ARRAY )) {
6820
+ return 1 ;
6821
+ }
6822
+
6823
+ return 0 ;
6824
+ }
6825
+ /* }}} */
6826
+
6817
6827
static inline zend_bool zend_try_ct_eval_binary_op (zval * result , uint32_t opcode , zval * op1 , zval * op2 ) /* {{{ */
6818
6828
{
6819
6829
binary_op_type fn = get_binary_op (opcode );
@@ -6831,6 +6841,10 @@ static inline zend_bool zend_try_ct_eval_binary_op(zval *result, uint32_t opcode
6831
6841
if (zend_binary_op_produces_numeric_string_error (opcode , op1 , op2 )) {
6832
6842
return 0 ;
6833
6843
}
6844
+ /* don't evaluate array to string conversions at compile-time */
6845
+ if (zend_binary_op_produces_array_conversion_error (opcode , op1 , op2 )) {
6846
+ return 0 ;
6847
+ }
6834
6848
6835
6849
fn (result , op1 , op2 );
6836
6850
return 1 ;
@@ -7000,10 +7014,18 @@ void zend_compile_binary_op(znode *result, zend_ast *ast) /* {{{ */
7000
7014
if (opcode == ZEND_CONCAT ) {
7001
7015
/* convert constant operands to strings at compile-time */
7002
7016
if (left_node .op_type == IS_CONST ) {
7003
- convert_to_string (& left_node .u .constant );
7017
+ if (Z_TYPE (left_node .u .constant ) == IS_ARRAY ) {
7018
+ zend_emit_op_tmp (& left_node , ZEND_CAST , & left_node , NULL )-> extended_value = IS_STRING ;
7019
+ } else {
7020
+ convert_to_string (& left_node .u .constant );
7021
+ }
7004
7022
}
7005
7023
if (right_node .op_type == IS_CONST ) {
7006
- convert_to_string (& right_node .u .constant );
7024
+ if (Z_TYPE (right_node .u .constant ) == IS_ARRAY ) {
7025
+ zend_emit_op_tmp (& right_node , ZEND_CAST , & right_node , NULL )-> extended_value = IS_STRING ;
7026
+ } else {
7027
+ convert_to_string (& right_node .u .constant );
7028
+ }
7007
7029
}
7008
7030
if (left_node .op_type == IS_CONST && right_node .op_type == IS_CONST ) {
7009
7031
opcode = ZEND_FAST_CONCAT ;
0 commit comments