PHP :: Bug #76717 :: var_export() does not create a parsable value for PHP_INT_MIN
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: Verified Package: Unknown/Other Function
PHP Version: 7.3.0beta1 OS: All
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [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

Add a Patch

Pull Requests

Add a Pull Request

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.
 
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Thu Aug 16 12:01:24 2018 UTC