3 ms·
I had some very similar, very troubling PHP code. var_export($var) // 18 json_encode($var) // 18 serialize($var) // 18i:18; var_export($var == 18) // f
by donatj 11y ago
I had some very similar, very troubling PHP code.
var_export($var) // 18
json_encode($var) // 18
serialize($var) // 18i:18;
var_export($var == 18) // false
var_export(floor($var)) // 17
Ends up PHP floats have a configurable precision and an actual physical 32/62 bit (depending on the system) in memory value who are separate and some operations use one and some the other. It was particularly troubling because I'd hope to be able to serialize and unserialize numbers losslessly but that was not the case.
- lsaferite 11y agoCan you provide a working 3v4l.org example of this issue? I'm very interested is what triggered it to not output the correct values for json_encode and serialize.