php / php/doc-en

Incorrect behavior of literal value of PHP_INT_MIN

Open
#2,400 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug Status: Needs Triage
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";

See https://3v4l.org/QpWHc

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
  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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.