php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66179 var_export() exports float as integer
Submitted: 2013-11-26 15:56 UTC Modified: 2016-01-18 21:06 UTC
Votes:4
Avg. Score:3.0 ± 1.4
Reproduced:3 of 3 (100.0%)
Same Version:2 (66.7%)
Same OS:2 (66.7%)
From: david at grudl dot com Assigned: ajf (profile)
Status: Closed Package: Variables related
PHP Version: 5.5.6 OS:
Private report: No CVE-ID: None
 [2013-11-26 15:56 UTC] david at grudl dot com
Description:
------------
var_export(1.0) returns "1" instead of "1.0" in all PHP versions 


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-11-27 09:41 UTC] utkarsh dot parekh at yahoo dot in
If you try this var_export(2.1245) returns "2.1245". It is right.
 [2013-11-29 22:30 UTC] bwoebi@php.net
-Status: Open +Status: Not a bug
 [2013-11-29 22:30 UTC] bwoebi@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

A float(1.0) is stored as a float(1) (it's the same), so var_export(1.0) outputs 1.
 [2014-07-03 16:48 UTC] vrana@php.net
-Status: Not a bug +Status: Re-Opened
 [2014-07-03 16:48 UTC] vrana@php.net
($a === eval('return ' . var_export($a, true) . ';')) should result in true for any given $a. "1" isn't a correct representation of float(1) as it results in int(1).
 [2015-06-29 18:57 UTC] xuefer at gmail dot com
Not sure if this is the same problem

http://3v4l.org/ZRPXO

var_export(5.3); echo "\n";
var_dump(5.3); echo "\n";

outputs:
5.29999999999999982236432
float(5.3)

in this case luckily 5.29999999999999982236432 == 5.3, and it pass ($a === eval('return ' . var_export($a, true) . ';')) definition
but i give this example to show that var_dump is better (looking) than var_export on double value

so please take it seriously
 [2015-12-18 17:27 UTC] ajf@php.net
-Status: Re-Opened +Status: Assigned -Assigned To: +Assigned To: ajf
 [2015-12-18 19:31 UTC] ajf@php.net
Automatic comment on behalf of ajf@ajf.me
Revision: http://git.php.net/?p=php-src.git;a=commit;h=8d217db369d83de22db6c2e6ad9a440d6c59518f
Log: Fix bug #66179
 [2015-12-18 19:31 UTC] ajf@php.net
-Status: Assigned +Status: Closed
 [2015-12-18 19:32 UTC] ajf@php.net
Automatic comment on behalf of ajf@ajf.me
Revision: http://git.php.net/?p=php-src.git;a=commit;h=8d217db369d83de22db6c2e6ad9a440d6c59518f
Log: Fix bug #66179
 [2016-01-08 17:20 UTC] ajf@php.net
Thank you for your bug report. This issue has already been fixed
in the latest released version of PHP, which you can download at 
http://www.php.net/downloads.php

Fixed in 7.0.2. Unfortunately, I screwed up the fix, creating bug #71314.
 [2016-01-18 18:42 UTC] lisachenko dot it at gmail dot com
I think, that Reflection should also use this new logic for exporting float numbers: check https://3v4l.org/2JFbL

This will be consistent with current var_export behavior.
 [2016-01-18 21:06 UTC] ajf@php.net
That sounds like a good idea, maybe it should be a separate bug report.
 [2016-07-20 11:34 UTC] davey@php.net
Automatic comment on behalf of ajf@ajf.me
Revision: http://git.php.net/?p=php-src.git;a=commit;h=8d217db369d83de22db6c2e6ad9a440d6c59518f
Log: Fix bug #66179
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 10:01:29 2024 UTC