Make var_dump() use serialize_precision

From: Date: Tue, 18 Feb 2020 11:20:18 +0000
Subject: Make var_dump() use serialize_precision
Groups: php.internals 
Request: Send a blank email to internals+get-108655@lists.php.net to get a copy of this message
Hi internals, https://github.com/php/php-src/pull/5172 changes var_dump() to use serialize_precision instead of precision to dump floating-point numbers. To recap: serialize_precision defaults to -1, which will print exactly as many floating-point digits as are needed to represent the number accurately. precision defaults to 14, which will print a shorter but potentially inaccurate float representation. The motivation here is that var_dump() is debugging functionality and should print values as accurately as possible. The single most common bug report we receive is some kind of variation on: $sum = 0.1 + 0.2; var_dump($sum); // float(0.3) var_dump($sum == 0.3); // bool(false) WTF??? After this change, this would instead be: $sum = 0.1 + 0.2; var_dump($sum); // float(0.30000000000000004) var_dump($sum == 0.3); // bool(false) Makes sense... I have little hope that developers will suddenly start understanding floating-point numbers, but at least this should reduce the amount of confusion. Does anyone see an issue with doing this change? Regards, Nikita

« previous php.internals (#108655) next »