Bug #76717 [Ver->Csd]: var_export() does not create a parsable value for PHP_INT_MIN
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: Verified
+Status: Closed
Type: Bug
Package: Unknown/Other Function
Operating System: All
PHP Version: 7.3.0beta1
Block user comment: N
Private report: N
New Comment:
Automatic comment on behalf of nikita.ppv@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=1fd32e9c2f15eabdc7e531b1fa76f62fc5a8ca75
Log: Fixed bug #76717
Previous Comments:
------------------------------------------------------------------------
[2018-08-07 18:05:46] nikic@php.net
Nice catch. We should probably generate -9223372036854775807-1.
------------------------------------------------------------------------
[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
Thread (3 messages)