php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71451 var_export() wrong output
Submitted: 2016-01-26 08:15 UTC Modified: 2016-02-08 01:40 UTC
From: nask0 at cod3r dot net Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.6.17 OS: Fedora release 23 (Twenty Three)
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: nask0 at cod3r dot net
New email:
PHP Version: OS:

 

 [2016-01-26 08:15 UTC] nask0 at cod3r dot net
Description:
------------
var_export(1.001) outputs 1.0009999999999999 instead of 1.001


Test script:
---------------
Run in CLI :
php -r "var_export(1.001); echo \"\n\"; var_dump(1.001);"

Expected result:
----------------
1.001
double(1.001)

Actual result:
--------------
1.0009999999999999
double(1.001)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-01-26 13:47 UTC] rasmus@php.net
-Status: Open +Status: Not a bug
 [2016-01-26 13:47 UTC] rasmus@php.net
This is because var_export() is a serialization function and thus uses the serialization_precision setting. Try this:

php -d serialize_precision=14 -r 'var_export(1.001); echo "\n" ; var_dump(1.001);'

If you set your precision and serialize_precision to the same value you will get the same output from var_dump() and var_export(). var_dump() is not a serialization function since its output can't be read back in by anything. It is just for display purposes.
 [2016-02-08 01:40 UTC] yohgaki@php.net
This is not a bug, but there is RFC for this

https://wiki.php.net/rfc/precise_float_value

JSON numeric defacto standard representation is a concern also.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Wed Oct 07 08:00:02 2026 UTC