php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76717 var_export() does not create a parsable value for PHP_INT_MIN
Submitted: 2018-08-07 17:30 UTC Modified: 2018-08-07 18:05 UTC
From: fredemmott@php.net Assigned:
Status: Closed Package: Unknown/Other Function
PHP Version: 7.3.0beta1 OS: All
Private report: No CVE-ID: None
 [2018-08-07 17:30 UTC] 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)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-08-07 18:05 UTC] nikic@php.net
-Status: Open +Status: Verified
 [2018-08-07 18:05 UTC] nikic@php.net
Nice catch. We should probably generate -9223372036854775807-1.
 [2019-03-11 14:37 UTC] nikic@php.net
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
 [2019-03-11 14:37 UTC] nikic@php.net
-Status: Verified +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 09:01:32 2024 UTC