Skip to content

Commit

Permalink
Use serialize_precision for var_dump()
Browse files Browse the repository at this point in the history
var_dump() is debugging functionality, so it should print
floating-point numbers accurately. We do this by switching
to serialize_precision, which (by default) will print with
as much precision as necessary to preserve the exact value
of the float.

This also affects debug_zval_dump().

Closes phpGH-5172.
  • Loading branch information
nikic committed Feb 25, 2020
1 parent c3aa913 commit a939805
Show file tree
Hide file tree
Showing 111 changed files with 1,472 additions and 1,465 deletions.
4 changes: 4 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,10 @@ PHP 8.0 UPGRADE NOTES
http://example.com/foo?# => query = "", fragment = ""

Previously all cases resulted in query and fragment being null.
. var_dump() and debug_zval_dump() will now print floating-point numbers
using serialize_precision rather than precision. In a default configuration,
this means that floating-point numbers are now printed with full accuracy
by these debugging functions.

- tidy:
. The $use_include_path parameter, which was not used internally, has been
Expand Down
4 changes: 2 additions & 2 deletions Zend/tests/add_005.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ var_dump($c);
echo "Done\n";
?>
--EXPECT--
float(2834756759.1231)
float(2834756759.1231)
float(2834756759.123123)
float(2834756759.123123)
Done
44 changes: 21 additions & 23 deletions Zend/tests/binary-32bit.phpt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
--TEST--
testing binary literals
--INI--
precision=14
--SKIPIF--
<?php if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only"); ?>
--FILE--
Expand Down Expand Up @@ -126,27 +124,27 @@ float(8796093022207)
float(17592186044415)
float(35184372088831)
float(70368744177663)
float(1.4073748835533E+14)
float(2.8147497671066E+14)
float(5.6294995342131E+14)
float(1.1258999068426E+15)
float(2.2517998136852E+15)
float(4.5035996273705E+15)
float(9.007199254741E+15)
float(1.8014398509482E+16)
float(3.6028797018964E+16)
float(7.2057594037928E+16)
float(1.4411518807586E+17)
float(2.8823037615171E+17)
float(5.7646075230342E+17)
float(1.1529215046068E+18)
float(2.3058430092137E+18)
float(4.6116860184274E+18)
float(9.2233720368548E+18)
float(1.844674407371E+19)
float(-1.844674407371E+19)
float(-9.2233720368548E+18)
float(-4.6116860184274E+18)
float(140737488355327)
float(281474976710655)
float(562949953421311)
float(1125899906842623)
float(2251799813685247)
float(4503599627370495)
float(9007199254740992)
float(18014398509481984)
float(36028797018963970)
float(72057594037927940)
float(1.4411518807585587E+17)
float(2.8823037615171174E+17)
float(5.764607523034234E+17)
float(1.1529215046068468E+18)
float(2.3058430092136937E+18)
float(4.6116860184273874E+18)
float(9.223372036854775E+18)
float(1.844674407370955E+19)
float(-1.844674407370955E+19)
float(-9.223372036854775E+18)
float(-4.6116860184273874E+18)
float(-8589934591)
float(-4294967295)
int(-2147483647)
Expand Down
12 changes: 6 additions & 6 deletions Zend/tests/binary.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,12 @@ int(1152921504606846975)
int(2305843009213693951)
int(4611686018427387903)
int(9223372036854775807)
float(9223372036854775808)
float(18446744073709549568)
float(18446744073709549568)
float(36893488147419099136)
float(36893488147419099136)
float(-18446744073709549568)
float(9.223372036854776E+18)
float(1.844674407370955E+19)
float(1.844674407370955E+19)
float(3.68934881474191E+19)
float(3.68934881474191E+19)
float(-1.844674407370955E+19)
int(-9223372036854775807)
int(-4611686018427387903)
int(-1)
4 changes: 2 additions & 2 deletions Zend/tests/decrement_001_64bit.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ object(stdClass)#%d (0) {
}
array(0) {
}
float(-9.2233720368548E+18)
float(-9.2233720368548E+18)
float(-9.223372036854776E+18)
float(-9.223372036854776E+18)
Done
6 changes: 3 additions & 3 deletions Zend/tests/div_001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var_dump($c);
echo "Done\n";
?>
--EXPECT--
float(394758.39454545)
float(394758.39454545)
float(394758.39454545)
float(394758.39454545453)
float(394758.39454545453)
float(394758.39454545453)
Done
2 changes: 1 addition & 1 deletion Zend/tests/hex_overflow_32bit.phpt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
--TEST--
testing integer overflow (32bit)
--INI--
precision=14
serialize_precision=14
--SKIPIF--
<?php if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only"); ?>
--FILE--
Expand Down
4 changes: 2 additions & 2 deletions Zend/tests/numeric_string_errors.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ int(0)
Notice: A non well formed numeric value encountered in %s on line %d

Notice: A non well formed numeric value encountered in %s on line %d
float(0.89473684210526)
float(0.8947368421052632)

Warning: A non-numeric value encountered in %s on line %d

Expand All @@ -101,7 +101,7 @@ float(NAN)
Notice: A non well formed numeric value encountered in %s on line %d

Notice: A non well formed numeric value encountered in %s on line %d
float(3.0910586430935E+39)
float(3.0910586430935376E+39)

Warning: A non-numeric value encountered in %s on line %d

Expand Down
4 changes: 2 additions & 2 deletions Zend/tests/numeric_string_errors_assign.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ int(0)
Notice: A non well formed numeric value encountered in %s on line %d

Notice: A non well formed numeric value encountered in %s on line %d
float(0.89473684210526)
float(0.8947368421052632)

Warning: A non-numeric value encountered in %s on line %d

Expand All @@ -156,7 +156,7 @@ float(NAN)
Notice: A non well formed numeric value encountered in %s on line %d

Notice: A non well formed numeric value encountered in %s on line %d
float(3.0910586430935E+39)
float(3.0910586430935376E+39)

Warning: A non-numeric value encountered in %s on line %d

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ float(1)
*** Trying string(0) ""
*** Caught Return value of {closure}() must be of type float, string returned in %s on line %d
*** Trying int(9223372036854775807)
float(9.2233720368548E+18)
float(9.223372036854776E+18)
*** Trying float(NAN)
float(NAN)
*** Trying bool(true)
Expand Down
2 changes: 1 addition & 1 deletion Zend/tests/type_declarations/scalar_strict_64bit.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ float(1.5)
*** Caught {closure}() expects argument #1 ($f) to be of type float, string given, called in %s on line %d

*** Trying int(9223372036854775807)
float(9.2233720368548E+18)
float(9.223372036854776E+18)

*** Trying float(NAN)
float(NAN)
Expand Down
24 changes: 12 additions & 12 deletions Zend/tests/zend_signed_multiply-64bit-2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,27 @@ for($c = 0; $c <= 16; $c++) {
--EXPECT--
int(-16)
int(-922337203685477580)
float(1.4757395258968E+19)
float(1.4757395258967642E+19)
-----------
int(-15)
int(-922337203685477580)
float(1.3835058055282E+19)
float(1.3835058055282164E+19)
-----------
int(-14)
int(-922337203685477580)
float(1.2912720851597E+19)
float(1.2912720851596687E+19)
-----------
int(-13)
int(-922337203685477580)
float(1.1990383647911E+19)
float(1.1990383647911209E+19)
-----------
int(-12)
int(-922337203685477580)
float(1.1068046444226E+19)
float(1.1068046444225733E+19)
-----------
int(-11)
int(-922337203685477580)
float(1.014570924054E+19)
float(1.0145709240540254E+19)
-----------
int(-10)
int(-922337203685477580)
Expand Down Expand Up @@ -124,25 +124,25 @@ int(9223372036854775800)
-----------
int(11)
int(922337203685477580)
float(1.014570924054E+19)
float(1.0145709240540254E+19)
-----------
int(12)
int(922337203685477580)
float(1.1068046444226E+19)
float(1.1068046444225733E+19)
-----------
int(13)
int(922337203685477580)
float(1.1990383647911E+19)
float(1.1990383647911209E+19)
-----------
int(14)
int(922337203685477580)
float(1.2912720851597E+19)
float(1.2912720851596687E+19)
-----------
int(15)
int(922337203685477580)
float(1.3835058055282E+19)
float(1.3835058055282164E+19)
-----------
int(16)
int(922337203685477580)
float(1.4757395258968E+19)
float(1.4757395258967642E+19)
-----------
2 changes: 1 addition & 1 deletion Zend/tests/zend_signed_multiply-64bit.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ var_dump(0x80000001 * -0xffffffff);
--EXPECT--
int(-9223372034707292160)
int(9223372036854775806)
float(-9.2233720390023E+18)
float(-9.22337203900226E+18)
4 changes: 2 additions & 2 deletions Zend/tests/zend_strtod.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ echo "Done\n";
--EXPECT--
float(-100)
float(808792757210)
float(-4.5646456464565E+27)
float(-1.1276204760067E+16)
float(-4.5646456464564635E+27)
float(-11276204760067310)
Done
2 changes: 1 addition & 1 deletion ext/exif/tests/float_cast_overflow.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ array(8) {
["ImageWidth"]=>
int(1)
["ImageLength"]=>
float(-2.5961487387524E+33)
float(-2.5961487387524236E+33)
}
}
2 changes: 1 addition & 1 deletion ext/json/tests/008.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ var_dump($x->largenum);
echo "Done\n";
?>
--EXPECT--
float(1.2345678901235E+29)
float(1.2345678901234568E+29)
string(30) "123456789012345678901234567890"
Done
12 changes: 6 additions & 6 deletions ext/json/tests/bug63737.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ decode('-123456789012345678901234567890.1');
echo "Done\n";
?>
--EXPECT--
float(1.2345678901235E+29)
float(1.2345678901234568E+29)
string(30) "123456789012345678901234567890"
float(-1.2345678901235E+29)
float(-1.2345678901234568E+29)
string(31) "-123456789012345678901234567890"
float(1.2345678901235E+29)
float(1.2345678901235E+29)
float(-1.2345678901235E+29)
float(-1.2345678901235E+29)
float(1.2345678901234568E+29)
float(1.2345678901234568E+29)
float(-1.2345678901234568E+29)
float(-1.2345678901234568E+29)
Done
4 changes: 2 additions & 2 deletions ext/mysqli/tests/010.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ array(7) {
[2]=>
float(0)
[3]=>
float(1.0E+12)
float(1000000000000)
[4]=>
float(0.564642)
[5]=>
float(1)
[6]=>
float(8.88889E+14)
float(888889000000000)
}
done!
4 changes: 2 additions & 2 deletions ext/standard/tests/array/001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ array(11) {
[5]=>
string(6) "monkey"
[6]=>
float(-0.33333333333333)
float(-0.3333333333333333)
[7]=>
array(1) {
[0]=>
Expand Down Expand Up @@ -121,7 +121,7 @@ array(2) {
int(5)
string(6) "monkey"
int(6)
float(-0.33333333333333)
float(-0.3333333333333333)
int(7)
array(1) {
[0]=>
Expand Down
Loading

0 comments on commit a939805

Please sign in to comment.