Incorrect behavior of literal value of PHP_INT_MIN
Nobody has claimed this yet.
- Dominant language
- XML
- Stars
- 596
- Forks
- 890
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 55
Description
Description
PHP literal value of the minimal int64 overflows min bound value.
The following code:
<?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";
Resulted in this output:
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:
value: -9223372036854775808
literal: -9223372036854775808
eq: eq
value: 9223372036854775807
literal: 9223372036854775807
eq: eq
-9223372036854775808is valid int64 min value on x64 platform.-2147483648is 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
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue names no documentation file, test, or entry point. Start by checking the PHP integer and numeric-literal documentation against the reported 32-bit and 64-bit behavior. Done means identifying the relevant documentation location and confirming whether the behavior requires a documentation change.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- documentation
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100