Skip to content

Commit 41bbb11

Browse files
committed
Unary minus const expression consistency
- of 0.0 should result in -0.0 Closes GH-10978
1 parent 5e76c6d commit 41bbb11

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

NEWS

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 8.1.19
44

5+
- Core:
6+
. Fix inconsistent float negation in constant expressions. (ilutov)
7+
58
- DOM:
69
. Fixed bug #80602 (Segfault when using DOMChildNode::before()).
710
(Nathan Freeman)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
Unary minus constant expression consistency
3+
--FILE--
4+
<?php
5+
6+
const ZERO = 0.0;
7+
const MINUS_ZERO = -ZERO;
8+
$minus_zero = -ZERO;
9+
10+
var_dump(MINUS_ZERO);
11+
var_dump($minus_zero);
12+
13+
?>
14+
--EXPECT--
15+
float(-0)
16+
float(-0)

Zend/zend_ast.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -662,8 +662,8 @@ ZEND_API zend_result ZEND_FASTCALL zend_ast_evaluate(zval *result, zend_ast *ast
662662
if (UNEXPECTED(zend_ast_evaluate(&op2, ast->child[0], scope) != SUCCESS)) {
663663
ret = FAILURE;
664664
} else {
665-
ZVAL_LONG(&op1, 0);
666-
ret = sub_function(result, &op1, &op2);
665+
ZVAL_LONG(&op1, -1);
666+
ret = mul_function(result, &op1, &op2);
667667
zval_ptr_dtor_nogc(&op2);
668668
}
669669
break;

0 commit comments

Comments
 (0)