@@ -7216,14 +7216,32 @@ static zend_bool zend_try_ct_eval_magic_const(zval *zv, zend_ast *ast) /* {{{ */
7216
7216
}
7217
7217
/* }}} */
7218
7218
7219
- ZEND_API zend_bool zend_binary_op_produces_numeric_string_error (uint32_t opcode , zval * op1 , zval * op2 ) /* {{{ */
7219
+ ZEND_API zend_bool zend_binary_op_produces_error (uint32_t opcode , zval * op1 , zval * op2 ) /* {{{ */
7220
7220
{
7221
+ if ((opcode == ZEND_CONCAT || opcode == ZEND_FAST_CONCAT )) {
7222
+ /* Array to string warning. */
7223
+ return Z_TYPE_P (op1 ) == IS_ARRAY || Z_TYPE_P (op2 ) == IS_ARRAY ;
7224
+ }
7225
+
7221
7226
if (!(opcode == ZEND_ADD || opcode == ZEND_SUB || opcode == ZEND_MUL || opcode == ZEND_DIV
7222
- || opcode == ZEND_POW || opcode == ZEND_MOD || opcode == ZEND_SL || opcode == ZEND_SR
7223
- || opcode == ZEND_BW_OR || opcode == ZEND_BW_AND || opcode == ZEND_BW_XOR )) {
7227
+ || opcode == ZEND_POW || opcode == ZEND_MOD || opcode == ZEND_SL || opcode == ZEND_SR
7228
+ || opcode == ZEND_BW_OR || opcode == ZEND_BW_AND || opcode == ZEND_BW_XOR )) {
7229
+ /* Only the numeric operations throw errors. */
7224
7230
return 0 ;
7225
7231
}
7226
7232
7233
+ if (Z_TYPE_P (op1 ) == IS_ARRAY || Z_TYPE_P (op2 ) == IS_ARRAY ) {
7234
+ if (opcode == ZEND_ADD && Z_TYPE_P (op1 ) == IS_ARRAY && Z_TYPE_P (op2 ) == IS_ARRAY ) {
7235
+ /* Adding two arrays is allowed. */
7236
+ return 0 ;
7237
+ }
7238
+ if (opcode == ZEND_ADD || opcode == ZEND_SUB || opcode == ZEND_MUL || opcode == ZEND_POW
7239
+ || opcode == ZEND_DIV ) {
7240
+ /* These operators throw when one of the operands is an array. */
7241
+ return 1 ;
7242
+ }
7243
+ }
7244
+
7227
7245
/* While basic arithmetic operators always produce numeric string errors,
7228
7246
* bitwise operators don't produce errors if both operands are strings */
7229
7247
if ((opcode == ZEND_BW_OR || opcode == ZEND_BW_AND || opcode == ZEND_BW_XOR )
@@ -7241,13 +7259,12 @@ ZEND_API zend_bool zend_binary_op_produces_numeric_string_error(uint32_t opcode,
7241
7259
return 1 ;
7242
7260
}
7243
7261
7244
- return 0 ;
7245
- }
7246
- /* }}} */
7247
-
7248
- ZEND_API zend_bool zend_binary_op_produces_array_conversion_error (uint32_t opcode , zval * op1 , zval * op2 ) /* {{{ */
7249
- {
7250
- if (opcode == ZEND_CONCAT && (Z_TYPE_P (op1 ) == IS_ARRAY || Z_TYPE_P (op2 ) == IS_ARRAY )) {
7262
+ if ((opcode == ZEND_DIV || opcode == ZEND_MOD ) && zval_get_long (op2 ) == 0 ) {
7263
+ /* Division by zero throws an error. */
7264
+ return 1 ;
7265
+ }
7266
+ if ((opcode == ZEND_SL || opcode == ZEND_SR ) && zval_get_long (op2 ) < 0 ) {
7267
+ /* Shift by negative number throws an error. */
7251
7268
return 1 ;
7252
7269
}
7253
7270
@@ -7257,26 +7274,11 @@ ZEND_API zend_bool zend_binary_op_produces_array_conversion_error(uint32_t opcod
7257
7274
7258
7275
static inline zend_bool zend_try_ct_eval_binary_op (zval * result , uint32_t opcode , zval * op1 , zval * op2 ) /* {{{ */
7259
7276
{
7260
- binary_op_type fn = get_binary_op (opcode );
7261
-
7262
- /* don't evaluate division by zero at compile-time */
7263
- if ((opcode == ZEND_DIV || opcode == ZEND_MOD ) &&
7264
- zval_get_long (op2 ) == 0 ) {
7265
- return 0 ;
7266
- } else if ((opcode == ZEND_SL || opcode == ZEND_SR ) &&
7267
- zval_get_long (op2 ) < 0 ) {
7268
- return 0 ;
7269
- }
7270
-
7271
- /* don't evaluate numeric string error-producing operations at compile-time */
7272
- if (zend_binary_op_produces_numeric_string_error (opcode , op1 , op2 )) {
7273
- return 0 ;
7274
- }
7275
- /* don't evaluate array to string conversions at compile-time */
7276
- if (zend_binary_op_produces_array_conversion_error (opcode , op1 , op2 )) {
7277
+ if (zend_binary_op_produces_error (opcode , op1 , op2 )) {
7277
7278
return 0 ;
7278
7279
}
7279
7280
7281
+ binary_op_type fn = get_binary_op (opcode );
7280
7282
fn (result , op1 , op2 );
7281
7283
return 1 ;
7282
7284
}
0 commit comments