Doc #78081 [Opn->Dup]: Cannot write literal -9223372036854775808, do -922..807 - 1 instead

From: Date: Wed, 29 May 2019 07:55:23 +0000
Subject: Doc #78081 [Opn->Dup]: Cannot write literal -9223372036854775808, do -922..807 - 1 instead
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-16688@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=78081&edit=1 ID: 78081 Updated by: bwoebi@php.net Reported by: memory dot agape at gmail dot com Summary: Cannot write literal -9223372036854775808, do -922..807 - 1 instead -Status: Open +Status: Duplicate Type: Documentation Problem Package: Variables related Operating System: MacOS PHP Version: 7.2.18 Block user comment: N Private report: N New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2019-05-29 07:00:36] requinix@php.net I don't see it mentioned anywhere. I'd at least expect a note on the integers page. ------------------------------------------------------------------------ [2019-05-29 06:41:21] 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 06:26:30] memory dot agape at gmail dot com Thank you for your quick reply! Is it information written in some document? ------------------------------------------------------------------------ [2019-05-29 06:10:29] 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 05:59:30] 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) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=78081&edit=1

« previous php.doc.bugs (#16688) next »