Skip to content

Promote warnings to errors in array_count_values() #4580

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion ext/standard/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
16 changes: 7 additions & 9 deletions ext/standard/tests/array/array_count_values.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
?>
Expand Down Expand Up @@ -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!
31 changes: 7 additions & 24 deletions ext/standard/tests/array/array_count_values2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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!
22 changes: 9 additions & 13 deletions ext/standard/tests/array/array_count_values_variation.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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--
<?php
unlink("array_count_file");
?>
--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