Edit report at https://bugs.php.net/bug.php?id=66866&edit=1
ID: 66866
Updated by: rasmus@php.net
Reported by: jan dot kahoun at heureka dot cz
Summary: Same output for float numbers when using variable
handling functions
Status: Open
-Type: Feature/Change Request
+Type: Documentation Problem
Package: Variables related
Operating System: CentOS release 6.4 (Final)
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
var_export() is fundamentally different from print_r() and var_dump() in that it is often used to
read data back in. As such it is closer to serialize() than the others which are display-only
functions. For display purposes PHP has the 'precision' ini setting and for
serialize-purposes we have serialize_precision. In you script, if you do:
echo ini_set('precision',ini_get('serialize_precision'));
At the top you should get the same value for all three.
But yes, this probably should be mentioned on the var_export doc page.
Previous Comments:
------------------------------------------------------------------------
[2014-03-09 17:21:23] jan dot kahoun at heureka dot cz
Description:
------------
I know that the floating point values have a limited precision and hence a value might not have the
same string representation after any processing. But it is possible to make var_dump(), print_r()
and var_export() functions to output same result for float numbers? Some times the different output
results leads to hard debuging ;-)
If this is not possible, please mention this "feature" in the documentation of the
functions.
Thank you.
Test script:
---------------
$x = 0.399999999999999855671006798729649744927883148193359375;
print_r($x);
var_export($x);
var_dump($x);
Expected result:
----------------
Same result for all functions:
print_r() = 0.399999999999999855671006798729649744927883148193359375
var_export() = 0.399999999999999855671006798729649744927883148193359375
var_dump() = float(0.399999999999999855671006798729649744927883148193359375)
Actual result:
--------------
print_r() = 0.4
var_export() = 0.399999999999999855671006798729649744927883148193359375
var_dump() = float(0.4)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=66866&edit=1