php.net |  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 Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
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
Description:
------------
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:
---------------
<?php
 
var_dump(PHP_INT_MIN);
var_dump(-9223372036854775808);
var_dump((int) -9223372036854775808);
var_dump(-9223372036854775807);
var_dump(PHP_INT_MAX);
var_dump(9223372036854775807);

?>

Expected result:
----------------
int(-9223372036854775808)
int(-9223372036854775808)
int(-9223372036854775808)
int(-9223372036854775807)
int(9223372036854775807)
int(9223372036854775807)


Actual result:
--------------
int(-9223372036854775808)
double(-9.2233720368548E+18)
int(-9223372036854775808)
int(-9223372036854775807)
int(9223372036854775807)
int(9223372036854775807)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-05-29 06:10 UTC] requinix@php.net
-Status: Open +Status: Not a bug -Package: *General Issues +Package: Scripting Engine problem
 [2019-05-29 06:10 UTC] requinix@php.net
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] requinix@php.net
...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] requinix@php.net
-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] requinix@php.net
I don't see it mentioned anywhere. I'd at least expect a note on the integers page.
 [2019-05-29 07:55 UTC] bwoebi@php.net
-Status: Open +Status: Duplicate
 [2019-05-29 07:55 UTC] bwoebi@php.net
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-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 06:01:30 2024 UTC