From da06e250e6013bf343d4f89b7c5eb197dae84486 Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Wed, 21 Aug 2019 01:25:55 +0200 Subject: [PATCH] Promote warnings to errors in array_count_values() --- ext/standard/array.c | 3 +- .../tests/array/array_count_values.phpt | 16 +++++----- .../tests/array/array_count_values2.phpt | 31 +++++-------------- .../array/array_count_values_variation.phpt | 22 ++++++------- 4 files changed, 25 insertions(+), 47 deletions(-) diff --git a/ext/standard/array.c b/ext/standard/array.c index 70523d479ef4f..9a4d13afe8907 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -4101,7 +4101,8 @@ PHP_FUNCTION(array_count_values) Z_LVAL_P(tmp)++; } } else { - php_error_docref(NULL, E_WARNING, "Can only count STRING and INTEGER values!"); + zend_type_error("Can only count STRING and INTEGER values!"); + return; } } ZEND_HASH_FOREACH_END(); } diff --git a/ext/standard/tests/array/array_count_values.phpt b/ext/standard/tests/array/array_count_values.phpt index a6424aab9a6aa..fe041640e9dd4 100644 --- a/ext/standard/tests/array/array_count_values.phpt +++ b/ext/standard/tests/array/array_count_values.phpt @@ -18,7 +18,11 @@ $arrays = array ( ); foreach ($arrays as $item) { - var_dump (@array_count_values ($item)); + try { + var_dump (array_count_values ($item)); + } catch (\TypeError $e) { + echo $e->getMessage() . "\n"; + } echo "\n"; } ?> @@ -83,12 +87,6 @@ array(3) { int(4) } -array(1) { - [0]=> - int(1) -} +Can only count STRING and INTEGER values! -array(1) { - [1]=> - int(1) -} +Can only count STRING and INTEGER values! diff --git a/ext/standard/tests/array/array_count_values2.phpt b/ext/standard/tests/array/array_count_values2.phpt index 8aaf445f932ca..edce8142e2894 100644 --- a/ext/standard/tests/array/array_count_values2.phpt +++ b/ext/standard/tests/array/array_count_values2.phpt @@ -15,29 +15,12 @@ $array1 = array(1, FALSE, NULL, 0); -var_dump(array_count_values($array1)); -?> ---EXPECTF-- -Warning: array_count_values(): Can only count STRING and INTEGER values! in %s on line %d - -Warning: array_count_values(): Can only count STRING and INTEGER values! in %s on line %d -Warning: array_count_values(): Can only count STRING and INTEGER values! in %s on line %d -array(8) { - [1]=> - int(2) - ["hello"]=> - int(2) - ["world"]=> - int(1) - [""]=> - int(1) - ["rabbit"]=> - int(1) - ["foo"]=> - int(1) - ["Foo"]=> - int(1) - [0]=> - int(1) +try { + var_dump(array_count_values($array1)); +} catch (\TypeError $e) { + echo $e->getMessage() . "\n"; } +?> +--EXPECT-- +Can only count STRING and INTEGER values! diff --git a/ext/standard/tests/array/array_count_values_variation.phpt b/ext/standard/tests/array/array_count_values_variation.phpt index 00f13c8a5b7a9..d9eaa6c6c15a0 100644 --- a/ext/standard/tests/array/array_count_values_variation.phpt +++ b/ext/standard/tests/array/array_count_values_variation.phpt @@ -26,25 +26,21 @@ $fp = fopen("array_count_file", "w+"); $arrays = array ("bobk" => "bobv", "val", 6 => "val6", $fp, $ob); -var_dump (@array_count_values ($arrays)); -echo "\n"; - +try { + var_dump (array_count_values ($arrays)); +} catch (\TypeError $e) { + echo $e->getMessage() . "\n"; +} -echo "Done"; ?> + +DONE --CLEAN-- --EXPECT-- *** Testing array_count_values() : parameter variations *** -array(3) { - ["bobv"]=> - int(1) - ["val"]=> - int(1) - ["val6"]=> - int(1) -} +Can only count STRING and INTEGER values! -Done +DONE