Bug #76717 [Opn->Ver]: var_export() does not create a parsable value for PHP_INT_MIN
| From: | nikic@php.net | Date: | Tue, 07 Aug 2018 18:05:46 +0000 |
| Subject: | Bug #76717 [Opn->Ver]: var_export() does not create a parsable value for PHP_INT_MIN | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-216669@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=76717&edit=1
ID: 76717
Updated by: nikic@php.net
Reported by: fredemmott@php.net
Summary: var_export() does not create a parsable value for
PHP_INT_MIN
-Status: Open
+Status: Verified
Type: Bug
Package: Unknown/Other Function
Operating System: All
PHP Version: 7.3.0beta1
Block user comment: N
Private report: N
New Comment:
Nice catch. We should probably generate -9223372036854775807-1.
Previous Comments:
------------------------------------------------------------------------
[2018-08-07 17:30:11] fredemmott@php.net
Description:
------------
var_export() is documented as "Outputs or returns a parsable string representation of a
variable"
It generates an unparseable value for PHP_INT_MIN: it renders it as a negative decimal.
-x is not a negative literal; it's a unary op on x.
var_export generates '-9223372036854775808' - but as '9223372036854775808' is
greater PHP_INT_MAX, this generates a float.
Test script:
---------------
<?php
var_export(PHP_INT_MIN);
echo "\n";
var_export(PHP_INT_MAX);
echo "\n";
$min = eval('return '.var_export(PHP_INT_MIN, true).';');
$max = eval('return '.var_export(PHP_INT_MAX, true).';');
var_dump($min === PHP_INT_MIN);
var_dump($max === PHP_INT_MAX);
var_dump($min);
var_dump($max);
Expected result:
----------------
The last 4 lines of output should be true, true, (an int: value of PHP_INT_MIN), (an int: value of
PHP_INT_MAX)
Actual result:
--------------
-9223372036854775808
9223372036854775807
bool(false)
bool(true)
float(-9.2233720368548E+18)
int(9223372036854775807)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=76717&edit=1