]> granicus.if.org Git - php/commitdiff
Fix short-circuting (bug #69825)
authorBob Weinand <bobwei9@hotmail.com>
Sun, 14 Jun 2015 00:00:55 +0000 (02:00 +0200)
committerBob Weinand <bobwei9@hotmail.com>
Sun, 14 Jun 2015 00:00:55 +0000 (02:00 +0200)
Zend/tests/bug69825.phpt [new file with mode: 0644]
Zend/zend_compile.c

diff --git a/Zend/tests/bug69825.phpt b/Zend/tests/bug69825.phpt
new file mode 100644 (file)
index 0000000..1349dee
--- /dev/null
@@ -0,0 +1,30 @@
+--TEST--
+Bug #69825 (Short-circuiting failure)
+--FILE--
+<?php
+
+print "AND\n";
+var_dump(0 && 1);
+var_dump(0 && 0);
+var_dump(1 && 0);
+var_dump(1 && 1);
+
+print "OR\n";
+var_dump(0 || 1);
+var_dump(0 || 0);
+var_dump(1 || 0);
+var_dump(1 || 1);
+
+?>
+--EXPECT--
+AND
+bool(false)
+bool(false)
+bool(false)
+bool(true)
+OR
+bool(true)
+bool(false)
+bool(true)
+bool(true)
+
index 7e25c89781ef7ba83f41a48e4b971a6d1bd9baf2..f753af4483a4ebf31f45256e083c964322af8d32 100644 (file)
@@ -5854,7 +5854,10 @@ void zend_compile_short_circuiting(znode *result, zend_ast *ast) /* {{{ */
 
        zend_compile_expr(&right_node, right_ast);
 
-       if (right_node.op_type == IS_CONST) {
+       if (right_node.op_type == IS_CONST && (
+              (ast->kind == ZEND_AST_AND && !zend_is_true(&right_node.u.constant))
+           || (ast->kind == ZEND_AST_OR && zend_is_true(&right_node.u.constant))
+       )) {
                result->op_type = IS_CONST;
                ZVAL_BOOL(&result->u.constant, zend_is_true(&right_node.u.constant));
                zval_ptr_dtor(&right_node.u.constant);