[php-src] Issue #10998: Incorrect behavior of lateral value of PHP_INT_MIN

From: Date: Mon, 03 Apr 2023 00:35:07 +0000
Subject: [php-src] Issue #10998: Incorrect behavior of lateral value of PHP_INT_MIN
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-244083@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/10998 Author: SerafimArts ### Description PHP literal value of the minimal int64 overflows bound value. The following code: ```php <?php echo 'value: ' . \PHP_INT_MIN . "\n" . 'literal: ' . -9223372036854775808 . "\n" . 'eq: ' . (-9223372036854775808 === \PHP_INT_MIN ? 'eq' : 'neq') . "\n"; echo 'value: ' . \PHP_INT_MAX . "\n" . 'literal: ' . 9223372036854775807 . "\n" . 'eq: ' . (9223372036854775807 === \PHP_INT_MAX ? 'eq' : 'neq') . "\n"; ``` See https://3v4l.org/QpWHc Resulted in this output: ```yaml value: -9223372036854775808 literal: -9.2233720368548E+18 eq: neq value: 9223372036854775807 literal: 9223372036854775807 eq: eq # Exactly the same behavior with int32 (if rewrite assertions and run on x86 environment): value: -2147483648 literal: -2147483648 # <<< Note that in this case, the literal is displayed "as is", # however, the equivalence with the PHP_INT_MIN is still violated eq: neq value: 2147483647 literal: 2147483647 eq: eq ``` But I expected this output instead: ```yaml value: -9223372036854775808 literal: -9223372036854775808 eq: eq value: 9223372036854775807 literal: 9223372036854775807 eq: eq ``` 1) -9223372036854775808 is valid int64 min value on x64 platform. 2) -2147483648 is valid int32 min value on x86 platform. All versions of PHP (checked since php 7.0) are affected by this bug. This error is reproduced both on Debian linux and on Windows (checked for win11). ### PHP Version 7.0.0 ... 8.2.4 (Any) ### Operating System _No response_

« previous php.bugs (#244083) next »