@@ -9998,6 +9998,19 @@ ZEND_API bool zend_unary_op_produces_error(uint32_t opcode, const zval *op)
99989998 }
99999999 return Z_TYPE_P (op ) <= IS_TRUE || !zend_is_op_long_compatible (op );
1000010000 }
10001+ /* Can happen when called from zend_optimizer_eval_unary_op() */
10002+ if (
10003+ opcode == ZEND_IS_EQUAL
10004+ || opcode == ZEND_IS_NOT_EQUAL
10005+ || opcode == ZEND_BOOL
10006+ || opcode == ZEND_BOOL_NOT
10007+ ) {
10008+ /* BW_NOT on string does not convert the string into an integer. */
10009+ if (Z_TYPE_P (op ) == IS_DOUBLE ) {
10010+ return true;
10011+ }
10012+ return false;
10013+ }
1000110014
1000210015 return 0 ;
1000310016}
@@ -10181,7 +10194,7 @@ static void zend_compile_binary_op(znode *result, zend_ast *ast) /* {{{ */
1018110194 }
1018210195
1018310196 do {
10184- // TODO do not do this for NAN?
10197+ /* TODO: Do this optimization when other side is not float as NAN will warn and we don't want that
1018510198 if (opcode == ZEND_IS_EQUAL || opcode == ZEND_IS_NOT_EQUAL) {
1018610199 if (left_node.op_type == IS_CONST) {
1018710200 if (Z_TYPE(left_node.u.constant) == IS_FALSE) {
@@ -10204,7 +10217,8 @@ static void zend_compile_binary_op(znode *result, zend_ast *ast) /* {{{ */
1020410217 break;
1020510218 }
1020610219 }
10207- } else if (opcode == ZEND_IS_IDENTICAL || opcode == ZEND_IS_NOT_IDENTICAL ) {
10220+ } else */
10221+ if (opcode == ZEND_IS_IDENTICAL || opcode == ZEND_IS_NOT_IDENTICAL ) {
1020810222 /* convert $x === null to is_null($x) (i.e. ZEND_TYPE_CHECK opcode). Do the same thing for false/true. (covers IS_NULL, IS_FALSE, and IS_TRUE) */
1020910223 if (left_node .op_type == IS_CONST ) {
1021010224 if (Z_TYPE (left_node .u .constant ) <= IS_TRUE && Z_TYPE (left_node .u .constant ) >= IS_NULL ) {
@@ -12011,6 +12025,10 @@ static zend_op *zend_delayed_compile_var(znode *result, zend_ast *ast, uint32_t
1201112025
1201212026bool zend_try_ct_eval_cast (zval * result , uint32_t type , zval * op1 )
1201312027{
12028+ /* NAN warns when casting */
12029+ if (UNEXPECTED (Z_TYPE_P (op1 ) == IS_DOUBLE && zend_isnan (Z_DVAL_P (op1 )))) {
12030+ return false;
12031+ }
1201412032 switch (type ) {
1201512033 case _IS_BOOL :
1201612034 ZVAL_BOOL (result , zval_is_true (op1 ));
0 commit comments