From 974e361663f8734d32475a9c350bc53597f8f456 Mon Sep 17 00:00:00 2001 From: Tyson Andre Date: Sun, 17 Jan 2021 10:03:52 -0500 Subject: [PATCH] Proposal: Distinguish between float and int in print_r() output. Benefits: - print_r() previously make it look as if a value was an int when it really was a float, causing unintuitive, possibly caught TypeErrors This change should save time debugging in the long run. - print_r() output now shows a difference between 0.0 and 0, which is useful for generating line diffs in test failures. Cons: - Existing tests need to be changed if they involve the raw output of print_r and dumping float values. If this is merged, tests would need to normalize print_r output to pass in both 8.0 and 8.1 (or switch to var_dump(), etc.) --- Zend/zend.c | 17 +++ ext/date/tests/bug41709.phpt | 2 +- ext/date/tests/bug48678.phpt | 4 +- ext/date/tests/bug49081.phpt | 2 +- ext/date/tests/bug52738.phpt | 2 +- ext/date/tests/date-parse-by-format001.phpt | 4 +- .../tests/general_functions/print_r.phpt | 108 ++++++++--------- .../general_functions/print_r_64bit.phpt | 110 +++++++++--------- ext/standard/tests/strings/strcasecmp.phpt | Bin 20649 -> 20651 bytes ext/standard/tests/strings/strcmp.phpt | Bin 18464 -> 18466 bytes ext/standard/tests/url/bug77423.phpt | 2 + tests/lang/bug24640.phpt | 4 +- 12 files changed, 137 insertions(+), 118 deletions(-) diff --git a/Zend/zend.c b/Zend/zend.c index 22cdc744e6409..f17f99d95c49a 100644 --- a/Zend/zend.c +++ b/Zend/zend.c @@ -480,6 +480,23 @@ static void zend_print_zval_r_to_buf(smart_str *buf, zval *expr, int indent) /* case IS_LONG: smart_str_append_long(buf, Z_LVAL_P(expr)); break; + case IS_DOUBLE: + { + zend_string *str = zend_strpprintf_unchecked(0, "%.*H", (int) EG(precision), Z_DVAL_P(expr)); + smart_str_appends(buf, ZSTR_VAL(str)); + /* Without a decimal point, this can be mistaken for an integer, so add one. + * This check even works for scientific notation, because the + * mantissa always contains a decimal point. + * We need to check for finiteness, because INF, -INF and NAN + * must not have a decimal point added. + * (copied from php_var_export_ex, changed to only use helpers defined in Zend/) + */ + if (zend_finite(Z_DVAL_P(expr)) && NULL == strchr(ZSTR_VAL(str), '.')) { + smart_str_appendl(buf, ".0", 2); + } + zend_string_release_ex(str, 0); + break; + } case IS_REFERENCE: zend_print_zval_r_to_buf(buf, Z_REFVAL_P(expr), indent); break; diff --git a/ext/date/tests/bug41709.phpt b/ext/date/tests/bug41709.phpt index 624da0cd37fc6..beb913f7fa19c 100644 --- a/ext/date/tests/bug41709.phpt +++ b/ext/date/tests/bug41709.phpt @@ -17,7 +17,7 @@ Array [hour] => 0 [minute] => 0 [second] => 0 - [fraction] => 0 + [fraction] => 0.0 [warning_count] => 1 [warnings] => Array ( diff --git a/ext/date/tests/bug48678.phpt b/ext/date/tests/bug48678.phpt index 9c1cecd2df780..ba960ada6ee02 100644 --- a/ext/date/tests/bug48678.phpt +++ b/ext/date/tests/bug48678.phpt @@ -16,7 +16,7 @@ DateInterval Object [h] => 12 [i] => 30 [s] => 5 - [f] => 0 + [f] => 0.0 [weekday] => 0 [weekday_behavior] => 0 [first_last_day_of] => 0 @@ -35,7 +35,7 @@ DateInterval Object [h] => 12 [i] => 30 [s] => 5 - [f] => 0 + [f] => 0.0 [weekday] => 0 [weekday_behavior] => 0 [first_last_day_of] => 0 diff --git a/ext/date/tests/bug49081.phpt b/ext/date/tests/bug49081.phpt index b5d17a6c264b6..31c28e9602c81 100644 --- a/ext/date/tests/bug49081.phpt +++ b/ext/date/tests/bug49081.phpt @@ -17,7 +17,7 @@ DateInterval Object [h] => 4 [i] => 0 [s] => 0 - [f] => 0 + [f] => 0.0 [weekday] => 0 [weekday_behavior] => 0 [first_last_day_of] => 0 diff --git a/ext/date/tests/bug52738.phpt b/ext/date/tests/bug52738.phpt index 4f51fc38988a4..93bf914be3b46 100644 --- a/ext/date/tests/bug52738.phpt +++ b/ext/date/tests/bug52738.phpt @@ -28,7 +28,7 @@ di Object [h] => 0 [i] => 0 [s] => 0 - [f] => 0 + [f] => 0.0 [weekday] => 0 [weekday_behavior] => 0 [first_last_day_of] => 0 diff --git a/ext/date/tests/date-parse-by-format001.phpt b/ext/date/tests/date-parse-by-format001.phpt index 4431d2d30f92c..a7789bd5e3c16 100644 --- a/ext/date/tests/date-parse-by-format001.phpt +++ b/ext/date/tests/date-parse-by-format001.phpt @@ -15,7 +15,7 @@ Array [hour] => 0 [minute] => 0 [second] => 0 - [fraction] => 0 + [fraction] => 0.0 [warning_count] => 0 [warnings] => Array ( @@ -36,7 +36,7 @@ Array [hour] => 0 [minute] => 0 [second] => 0 - [fraction] => 0 + [fraction] => 0.0 [warning_count] => 0 [warnings] => Array ( diff --git a/ext/standard/tests/general_functions/print_r.phpt b/ext/standard/tests/general_functions/print_r.phpt index 0c0d77596109e..0f0c1aba07f1a 100644 --- a/ext/standard/tests/general_functions/print_r.phpt +++ b/ext/standard/tests/general_functions/print_r.phpt @@ -415,13 +415,13 @@ Array *** Testing print_r() on float variables *** -- Iteration 1 -- --0 --0 --0 +-0.0 +-0.0 +-0.0 -- Iteration 2 -- -0 -0 -0 +0.0 +0.0 +0.0 -- Iteration 3 -- 1.234 1.234 @@ -431,13 +431,13 @@ Array -1.234 -1.234 -- Iteration 5 -- --2 --2 --2 +-2.0 +-2.0 +-2.0 -- Iteration 6 -- -2 -2 -2 +2.0 +2.0 +2.0 -- Iteration 7 -- -0.5 -0.5 @@ -451,17 +451,17 @@ Array -0.00067 -0.00067 -- Iteration 10 -- --670 --670 --670 +-670.0 +-670.0 +-670.0 -- Iteration 11 -- -670 -670 -670 +670.0 +670.0 +670.0 -- Iteration 12 -- -670 -670 -670 +670.0 +670.0 +670.0 -- Iteration 13 -- -0.00410003 -0.00410003 @@ -479,13 +479,13 @@ Array 4100.003 4100.003 -- Iteration 17 -- -100000 -100000 -100000 +100000.0 +100000.0 +100000.0 -- Iteration 18 -- --100000 --100000 --100000 +-100000.0 +-100000.0 +-100000.0 -- Iteration 19 -- 1.0E-5 1.0E-5 @@ -495,29 +495,29 @@ Array -1.0E-5 -1.0E-5 -- Iteration 21 -- -100000 -100000 -100000 +100000.0 +100000.0 +100000.0 -- Iteration 22 -- --100000 --100000 --100000 +-100000.0 +-100000.0 +-100000.0 -- Iteration 23 -- -100000 -100000 -100000 +100000.0 +100000.0 +100000.0 -- Iteration 24 -- --100000 --100000 --100000 +-100000.0 +-100000.0 +-100000.0 -- Iteration 25 -- -100000 -100000 -100000 +100000.0 +100000.0 +100000.0 -- Iteration 26 -- --100000 --100000 --100000 +-100000.0 +-100000.0 +-100000.0 -- Iteration 27 -- 1.0E-5 1.0E-5 @@ -1578,7 +1578,7 @@ Array -- Iteration 4 -- Array ( - [0] => -0 + [0] => -0.0 [1] => Where am I? [2] => Array ( @@ -1594,7 +1594,7 @@ Array Array ( - [0] => -0 + [0] => -0.0 [1] => Where am I? [2] => Array ( @@ -1610,7 +1610,7 @@ Array Array ( - [0] => -0 + [0] => -0.0 [1] => Where am I? [2] => Array ( @@ -1628,7 +1628,7 @@ Array Array ( [0] => - [1] => 20000000000 + [1] => 20000000000.0 [2] => 79.1 [3] => 4.599998 ) @@ -1636,7 +1636,7 @@ Array Array ( [0] => - [1] => 20000000000 + [1] => 20000000000.0 [2] => 79.1 [3] => 4.599998 ) @@ -1644,7 +1644,7 @@ Array Array ( [0] => - [1] => 20000000000 + [1] => 20000000000.0 [2] => 79.1 [3] => 4.599998 ) @@ -1654,7 +1654,7 @@ Array ( [0] => array(1,2,3,4)1.0000002TRUE [1] => - [2] => 4611333 + [2] => 4611333.0 [3] => /00\7 ) @@ -1662,7 +1662,7 @@ Array ( [0] => array(1,2,3,4)1.0000002TRUE [1] => - [2] => 4611333 + [2] => 4611333.0 [3] => /00\7 ) @@ -1670,7 +1670,7 @@ Array ( [0] => array(1,2,3,4)1.0000002TRUE [1] => - [2] => 4611333 + [2] => 4611333.0 [3] => /00\7 ) diff --git a/ext/standard/tests/general_functions/print_r_64bit.phpt b/ext/standard/tests/general_functions/print_r_64bit.phpt index 56153e7682742..743d92657340b 100644 --- a/ext/standard/tests/general_functions/print_r_64bit.phpt +++ b/ext/standard/tests/general_functions/print_r_64bit.phpt @@ -419,13 +419,13 @@ Array *** Testing print_r() on float variables *** -- Iteration 1 -- --0 --0 --0 +-0.0 +-0.0 +-0.0 -- Iteration 2 -- -0 -0 -0 +0.0 +0.0 +0.0 -- Iteration 3 -- 1.234 1.234 @@ -435,13 +435,13 @@ Array -1.234 -1.234 -- Iteration 5 -- --2 --2 --2 +-2.0 +-2.0 +-2.0 -- Iteration 6 -- -2 -2 -2 +2.0 +2.0 +2.0 -- Iteration 7 -- -0.5 -0.5 @@ -455,17 +455,17 @@ Array -0.00067 -0.00067 -- Iteration 10 -- --670 --670 --670 +-670.0 +-670.0 +-670.0 -- Iteration 11 -- -670 -670 -670 +670.0 +670.0 +670.0 -- Iteration 12 -- -670 -670 -670 +670.0 +670.0 +670.0 -- Iteration 13 -- -0.00410003 -0.00410003 @@ -483,13 +483,13 @@ Array 4100.003 4100.003 -- Iteration 17 -- -100000 -100000 -100000 +100000.0 +100000.0 +100000.0 -- Iteration 18 -- --100000 --100000 --100000 +-100000.0 +-100000.0 +-100000.0 -- Iteration 19 -- 1.0E-5 1.0E-5 @@ -499,29 +499,29 @@ Array -1.0E-5 -1.0E-5 -- Iteration 21 -- -100000 -100000 -100000 +100000.0 +100000.0 +100000.0 -- Iteration 22 -- --100000 --100000 --100000 +-100000.0 +-100000.0 +-100000.0 -- Iteration 23 -- -100000 -100000 -100000 +100000.0 +100000.0 +100000.0 -- Iteration 24 -- --100000 --100000 --100000 +-100000.0 +-100000.0 +-100000.0 -- Iteration 25 -- -100000 -100000 -100000 +100000.0 +100000.0 +100000.0 -- Iteration 26 -- --100000 --100000 --100000 +-100000.0 +-100000.0 +-100000.0 -- Iteration 27 -- 1.0E-5 1.0E-5 @@ -1582,7 +1582,7 @@ Array -- Iteration 4 -- Array ( - [0] => -0 + [0] => -0.0 [1] => Where am I? [2] => Array ( @@ -1598,7 +1598,7 @@ Array Array ( - [0] => -0 + [0] => -0.0 [1] => Where am I? [2] => Array ( @@ -1614,7 +1614,7 @@ Array Array ( - [0] => -0 + [0] => -0.0 [1] => Where am I? [2] => Array ( @@ -1632,7 +1632,7 @@ Array Array ( [0] => - [1] => 20000000000 + [1] => 20000000000.0 [2] => 79.1 [3] => 4.599998 ) @@ -1640,7 +1640,7 @@ Array Array ( [0] => - [1] => 20000000000 + [1] => 20000000000.0 [2] => 79.1 [3] => 4.599998 ) @@ -1648,7 +1648,7 @@ Array Array ( [0] => - [1] => 20000000000 + [1] => 20000000000.0 [2] => 79.1 [3] => 4.599998 ) @@ -1658,7 +1658,7 @@ Array ( [0] => array(1,2,3,4)1.0000002TRUE [1] => - [2] => 4611333 + [2] => 4611333.0 [3] => /00\7 ) @@ -1666,7 +1666,7 @@ Array ( [0] => array(1,2,3,4)1.0000002TRUE [1] => - [2] => 4611333 + [2] => 4611333.0 [3] => /00\7 ) @@ -1674,7 +1674,7 @@ Array ( [0] => array(1,2,3,4)1.0000002TRUE [1] => - [2] => 4611333 + [2] => 4611333.0 [3] => /00\7 ) @@ -1695,4 +1695,4 @@ Array -- Iteration 4 -- -Done +Done \ No newline at end of file diff --git a/ext/standard/tests/strings/strcasecmp.phpt b/ext/standard/tests/strings/strcasecmp.phpt index 95a25bd6994a7c75a51a4ccdbaf8396d1f6f7632..a525496dc0e8d14c5f982aeddee9e7c2851a74a5 100644 GIT binary patch delta 17 ZcmZ3vka6`w#tj$knDh)bU$na+2mnNs2V(#L delta 14 WcmZ3zka6Wg#tj$kHea^8AqW69C --FILE--