# Introduce PHP_INT_MAX_SAFE constant similar to JS's Number.MAX_SAFE_INTEGER constant

- Thread: https://externals.io/message/128032
- Original archive: https://news-web.php.net/php.internals/128032
- Started by Gina P. Banyard on 2025-07-14T11:54:57+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #128032 — Gina P. Banyard — 2025-07-14T11:54:57+00:00

URL: https://externals.io/message/128032#128032

Hello internals,

I'm mailing the list for the bike shed of the naming of a new constant I think we should introduce in PHP which I'm currently calling PHP_INT_MAX_SAFE.
The purpose of this integer is to indicate what is the maximal integer value that can be correctly represented by a float.
On 32 bits this is equal to PHP_INT_MAX, but on 64 bits it is 9007199254740991 (which is 2^(53) – 1) as the mantissa of a floating point number is 52 bits.

For more information, please see the MDN documentation about Number.MAX_SAFE_INTEGER. [1]

The implementation is very simple and the PR is https://github.com/php/php-src/pull/19126

Best regards,

Gina P. Banyard

[1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER

---

## #128034 — tim@bastelstu.be — 2025-07-14T12:58:09+00:00

URL: https://externals.io/message/128032#128034 · In reply to: #128032

Hi

Am 2025-07-14 13:54, schrieb Gina P. Banyard:
> The purpose of this integer is to indicate what is the maximal integer 
> value that can be correctly represented by a float.
> On 32 bits this is equal to PHP_INT_MAX, but on 64 bits it is 
> 9007199254740991 (which is 2^(53) – 1) as the mantissa of a floating 
> point number is 52 bits.

I don't understand why this should be equal to `PHP_INT_MAX` for 32 Bit 
builds. The largest integer that can be safely represented by a float is 
2^53-1 for both 32 and 64 Bit builds of PHP. More generally, I do not 
understand the value of the constant. PHP has proper integers, whereas 
JavaScript does not.

Best regards
Tim Düsterhu

---

## #128209 — Alexandre Daubois — 2025-07-24T12:51:20+00:00

URL: https://externals.io/message/128032#128209 · In reply to: #128032

Hi Gina,

Le jeu. 24 juil. 2025 à 14:46, Gina P. Banyard <internals@gpb.moe> a écrit :
>
> Hello internals,
>
> I'm mailing the list for the bike shed of the naming of a new constant I think we should introduce in PHP which I'm currently calling PHP_INT_MAX_SAFE.
> The purpose of this integer is to indicate what is the maximal integer value that can be correctly represented by a float.
> On 32 bits this is equal to PHP_INT_MAX, but on 64 bits it is 9007199254740991 (which is 2^(53) – 1) as the mantissa of a floating point number is 52 bits.

What about an actual function returning if an integer is safe or not?
We actually ran into this lately with the JsonPath component of
Symfony. I wrote a userland function for this:
https://github.com/symfony/symfony/blob/d3a0df0243e1c68598fa066eaa6cd0cf39f256dc/src/Symfony/Component/JsonPath/JsonPathUtils.php#L243

Given the numerous interactions between PHP and JSON, I think it would
be useful to have a function like "is_safe_integer()".

Best,
Alex
