Re: [PHP-DEV] Make var_dump() use serialize_precision

2020-02-18 Thread Andreas Heigl


Am 18.02.20 um 12:20 schrieb Nikita Popov:
> 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.30004)
> 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?

You mean apart from people now filing bugs how var_dump() can output
such a nonsensical number from such an easy equation? And that it again
shows that PHP is not a real programming language (unlike JavaScript)
and should never be used at all?

Nope ;-)

Cheers

Andreas

PS: I'd absolutely appreciate the change!!!
-- 
  ,,,
 (o o)
+-ooO-(_)-Ooo-+
| Andreas Heigl   |
| mailto:andr...@heigl.org  N 50°22'59.5" E 08°23'58" |
| http://andreas.heigl.org   http://hei.gl/wiFKy7 |
+-+
| http://hei.gl/root-ca   |
+-+



signature.asc
Description: OpenPGP digital signature


[PHP-DEV] Make var_dump() use serialize_precision

2020-02-18 Thread Nikita Popov
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.30004)
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