php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72377 var_export bad number conversion
Submitted: 2016-06-10 12:31 UTC Modified: 2016-06-10 13:54 UTC
From: stefano dot galeazzi at probanet dot it Assigned: cmb (profile)
Status: Not a bug Package: *General Issues
PHP Version: 7.0.7 OS: Ubuntu 16.04, Arch Linux
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: stefano dot galeazzi at probanet dot it
New email:
PHP Version: OS:

 

 [2016-06-10 12:31 UTC] stefano dot galeazzi at probanet dot it
Description:
------------
var_export() makes unnecessary and wrong number conversions.

Test script:
---------------
php --version
PHP 7.0.7 (cli) (built: May 25 2016 18:40:26) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies

php -r 'echo(var_export(0.98) . "\n");'
0.97999999999999998


Expected result:
----------------
php -r 'echo(var_export(0.98) . "\n");'
0.98


Actual result:
--------------
php -r 'echo(var_export(0.98) . "\n");'
0.97999999999999998


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-06-10 12:45 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2016-06-10 12:45 UTC] cmb@php.net
Floating point values have a limited precision. Hence a value might 
not have the same string representation after any processing. That also
includes writing a floating point value in your script and directly 
printing it without any mathematical operations.

If you would like to know more about "floats" and what IEEE
754 is, read this:
http://www.floating-point-gui.de/

Thank you for your interest in PHP.


 [2016-06-10 13:33 UTC] stefano dot galeazzi at probanet dot it
No thanks (no time to be a master of floats), I just want it working, like it was in PHP 5.
 [2016-06-10 13:42 UTC] nikic@php.net
Change the serialize_precision setting to a lower value to restore the previous behavior. Note that this will also affect the output of serialize() and that the values exported in this way may not coincide with the original values.
 [2016-06-10 13:46 UTC] stefano dot galeazzi at probanet dot it
Thanks a lot!!! ^_^
 [2016-06-10 13:54 UTC] cmb@php.net
For the record: the behavior has changed as of PHP 5.4.22 and
5.5.6, respectively, as result of fixing bug #64760.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 16:01:29 2024 UTC