[doc-en] master: Explain why -9223372036854775808 is a float, not PHP_INT_MIN (#6092)
| From: | Asish Kumar via GitHub | Date: | Mon, 16 Nov 2026 08:50:29 +0000 |
| Subject: | [doc-en] master: Explain why -9223372036854775808 is a float, not PHP_INT_MIN (#6092) | ||
| Groups: | php.doc.cvs | ||
| Request: | Send a blank email to doc-cvs+get-23963@lists.php.net to get a copy of this message | ||
Author: Asish Kumar (officialasishkumar)
Committer: GitHub (web-flow)
Pusher: lacatoire
Date: 2026-11-16T09:50:25+01:00
Commit: https://github.com/php/doc-en/commit/1385c4175bb058d306e2064ea6e6ad84c43c81bc
Raw diff: https://github.com/php/doc-en/commit/1385c4175bb058d306e2064ea6e6ad84c43c81bc.diff
Explain why -9223372036854775808 is a float, not PHP_INT_MIN (#6092)
A negative int literal is a positive literal with the negation operator
applied to it. The literal 9223372036854775808 is beyond PHP_INT_MAX on
64-bit systems, so it is already a float when it is negated, and
-9223372036854775808 === PHP_INT_MIN is false. The same happens with
-2147483648 on 32-bit systems.
Add a paragraph and an example to the integer overflow section that
explain this and point to PHP_INT_MIN, or an expression such as
-9223372036854775807 - 1, instead. The example output was checked on
PHP 7.4, 8.5 and 8.6.
Fixes #2400
Changed paths:
M language/types/integer.xml
Diff:
diff --git a/language/types/integer.xml b/language/types/integer.xml
index 2aa16875bec0..569108455115 100644
--- a/language/types/integer.xml
+++ b/language/types/integer.xml
@@ -118,6 +118,34 @@ var_dump($large_number); // float(5.0E+19)
var_dump(PHP_INT_MAX + 1); // 32-bit system: float(2147483648)
// 64-bit system: float(9.2233720368548E+18)
?>
+]]>
+ </programlisting>
+ </example>
+
+ <simpara>
+ A negative <type>int</type> literal is a positive literal with the
+ <link linkend="language.operators.arithmetic">negation operator</link>
+ applied to it. This means that <constant>PHP_INT_MIN</constant> cannot be
+ written as a literal: in <literal>-9223372036854775808</literal>, the
+ literal <literal>9223372036854775808</literal> is beyond the bounds of the
+ <type>int</type> type on 64-bit systems, so it is interpreted as a
+ <type>float</type> before it is negated.
+ The same applies to <literal>-2147483648</literal> on 32-bit systems.
+ Use <constant>PHP_INT_MIN</constant> instead, or an expression such as
+ <literal>-9223372036854775807 - 1</literal>.
+ </simpara>
+
+ <example>
+ <title>The smallest <type>int</type></title>
+ <programlisting role="php">
+<![CDATA[
+<?php
+var_dump(-9223372036854775808); // 64-bit system: float(-9.223372036854776E+18)
+var_dump(-9223372036854775807 - 1); // 64-bit system: int(-9223372036854775808)
+
+var_dump(PHP_INT_MIN); // 32-bit system: int(-2147483648)
+ // 64-bit system: int(-9223372036854775808)
+?>
]]>
</programlisting>
</example>