|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #78081 Cannot write literal -9223372036854775808, do -922..807 - 1 instead
Submitted: 2019-05-29 05:59 UTC Modified: 2019-05-29 08:21 UTC
From: memory dot agape at gmail dot com Assigned:
Status: Duplicate Package: Variables related
PHP Version: 7.2.18 OS: MacOS
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: memory dot agape at gmail dot com
New email:
PHP Version: OS:


 [2019-05-29 05:59 UTC] memory dot agape at gmail dot com
I tried to output a negative value -9223372036854775808 but it will show a double type value.
It expected an integer value.

My PHP version is shown below:
> php -v
> PHP 7.2.18 (cli) (built: May 21 2019 20:18:44) ( NTS )
> Copyright (c) 1997-2018 The PHP Group
> Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
>     with Xdebug v2.7.2, Copyright (c) 2002-2019, by Derick Rethans
>     with Zend OPcache v7.2.18, Copyright (c) 1999-2018, by Zend Technologies

Test script:
var_dump((int) -9223372036854775808);


Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2019-05-29 06:10 UTC]
-Status: Open +Status: Not a bug -Package: *General Issues +Package: Scripting Engine problem
 [2019-05-29 06:10 UTC]
This is a quirk of how PHP parses code: -1 is actually the number 1 negated, and since -9223372036854775808 is too large for a positive integer it overflows to float and *then* is negated.

You cannot write -9223372036854775808 as a literal. Write -9223372036854775807 - 1 instead.
 [2019-05-29 06:26 UTC] memory dot agape at gmail dot com
Thank you for your quick reply!
Is it information written in some document?
 [2019-05-29 06:41 UTC]
...I don't know. Last time I remember this coming up it was from a bug report - in fact within the last month or so, I think.
 [2019-05-29 07:00 UTC]
-Summary: I tried to output -9223372036854775808 but it will show -9.2233720368548E+18 +Summary: Cannot write literal -9223372036854775808, do -922..807 - 1 instead -Status: Not a bug +Status: Open -Type: Bug +Type: Documentation Problem -Package: Scripting Engine problem +Package: Variables related
 [2019-05-29 07:00 UTC]
I don't see it mentioned anywhere. I'd at least expect a note on the integers page.
 [2019-05-29 07:55 UTC]
-Status: Open +Status: Duplicate
 [2019-05-29 07:55 UTC]
This behavior is somewhat known, also do write PHP_INT_MIN instead.

But yeah, I consider this somewhat unfortunate (especially in generated code, where I ended up having to write an explicit condition for if min value, then print PHP_INT_MIN, else the value...).
This should really be fixed in PHP itself, I think...

But for now marking as a dupe of #53934.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Fri May 07 05:01:42 2021 UTC