Skip to content

Commit

Permalink
Improve ArgumentCountError error message
Browse files Browse the repository at this point in the history
  • Loading branch information
kocsismate committed Aug 16, 2020
1 parent 14740f7 commit c0422ce
Show file tree
Hide file tree
Showing 36 changed files with 70 additions and 70 deletions.
2 changes: 1 addition & 1 deletion Zend/tests/bug46106.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ try {
?>
DONE
--EXPECT--
str_pad() expects at least 2 parameters, 1 given
str_pad(): At least 2 arguments are expected, 1 given
DONE
2 changes: 1 addition & 1 deletion Zend/tests/bug51827.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ register_shutdown_function('exploDe');
--EXPECT--
int(1)

Fatal error: Uncaught ArgumentCountError: explode() expects at least 2 parameters, 0 given in [no active file]:0
Fatal error: Uncaught ArgumentCountError: explode(): At least 2 arguments are expected, 0 given in [no active file]:0
Stack trace:
#0 [internal function]: explode()
#1 {main}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ try {
}
?>
--EXPECT--
substr() expects at least 2 parameters, 1 given
substr(): At least 2 arguments are expected, 1 given
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ try {
?>
--EXPECT--
ArgumentCountError
substr() expects at least 2 parameters, 1 given
substr(): At least 2 arguments are expected, 1 given
ArgumentCountError
At least 2 parameters are required, 1 given
40 changes: 20 additions & 20 deletions Zend/zend_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,18 +198,18 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameters_none_error(void) /*
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameters_count_error(uint32_t min_num_args, uint32_t max_num_args) /* {{{ */
{
uint32_t num_args = ZEND_CALL_NUM_ARGS(EG(current_execute_data));
zend_function *active_function = EG(current_execute_data)->func;
const char *class_name = active_function->common.scope ? ZSTR_VAL(active_function->common.scope->name) : "";
char *func_name = get_active_function_or_method_name();

zend_argument_count_error(
"%s%s%s() expects %s %d parameter%s, %d given",
class_name, \
class_name[0] ? "::" : "", \
ZSTR_VAL(active_function->common.function_name),
min_num_args == max_num_args ? "exactly" : num_args < min_num_args ? "at least" : "at most",
num_args < min_num_args ? min_num_args : max_num_args,
(num_args < min_num_args ? min_num_args : max_num_args) == 1 ? "" : "s",
num_args);
"%s(): %s %d argument%s %s expected, %d given",
func_name, min_num_args == max_num_args ? "Exactly" : num_args < min_num_args ? "At least" : "At most",
num_args < min_num_args ? min_num_args : max_num_args,
(num_args < min_num_args ? min_num_args : max_num_args) == 1 ? "" : "s",
(num_args < min_num_args ? min_num_args : max_num_args) == 1 ? "is" : "are",
num_args
);

efree(func_name);
}
/* }}} */

Expand Down Expand Up @@ -987,16 +987,16 @@ static int zend_parse_va_args(uint32_t num_args, const char *type_spec, va_list

if (num_args < min_num_args || num_args > max_num_args) {
if (!(flags & ZEND_PARSE_PARAMS_QUIET)) {
zend_function *active_function = EG(current_execute_data)->func;
const char *class_name = active_function->common.scope ? ZSTR_VAL(active_function->common.scope->name) : "";
zend_argument_count_error("%s%s%s() expects %s %d parameter%s, %d given",
class_name,
class_name[0] ? "::" : "",
ZSTR_VAL(active_function->common.function_name),
min_num_args == max_num_args ? "exactly" : num_args < min_num_args ? "at least" : "at most",
num_args < min_num_args ? min_num_args : max_num_args,
(num_args < min_num_args ? min_num_args : max_num_args) == 1 ? "" : "s",
num_args);
char *func_name = get_active_function_or_method_name();
zend_argument_count_error("%s(): %s %d argument%s %s expected, %d given",
func_name, min_num_args == max_num_args ? "Exactly" : num_args < min_num_args ? "At least" : "At most",
num_args < min_num_args ? min_num_args : max_num_args,
(num_args < min_num_args ? min_num_args : max_num_args) == 1 ? "" : "s",
(num_args < min_num_args ? min_num_args : max_num_args) == 1 ? "is" : "are",
num_args
);

efree(func_name);
}
return FAILURE;
}
Expand Down
2 changes: 1 addition & 1 deletion ext/date/tests/DateTimeZone_construct_error.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ try {
*** Testing DateTimeZone() : error conditions ***

-- Testing new DateTimeZone() with more than expected no. of arguments --
DateTimeZone::__construct() expects exactly 1 parameter, 2 given
DateTimeZone::__construct(): Exactly 1 argument is expected, 2 given
2 changes: 1 addition & 1 deletion ext/date/tests/DateTime_construct_error.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ try {
*** Testing date_create() : error conditions ***

-- Testing new DateTime() with more than expected no. of arguments --
DateTime::__construct() expects at most 2 parameters, 3 given
DateTime::__construct(): At most 2 arguments are expected, 3 given
4 changes: 2 additions & 2 deletions ext/date/tests/mktime_error.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ try {
*** Testing mktime() : error conditions ***

-- Testing mktime() function with Zero arguments --
mktime() expects at least 1 parameter, 0 given
mktime(): At least 1 argument is expected, 0 given

-- Testing mktime() function with more than expected no. of arguments --
mktime() expects at most 6 parameters, 7 given
mktime(): At most 6 arguments are expected, 7 given
4 changes: 2 additions & 2 deletions ext/spl/tests/CallbackFilterIteratorTest-002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ try {
}
?>
--EXPECT--
CallbackFilterIterator::__construct() expects exactly 2 parameters, 0 given
CallbackFilterIterator::__construct() expects exactly 2 parameters, 1 given
CallbackFilterIterator::__construct(): Exactly 2 arguments are expected, 0 given
CallbackFilterIterator::__construct(): Exactly 2 arguments are expected, 1 given
CallbackFilterIterator::__construct(): Argument #2 ($callback) must be a valid callback, no array or string given
CallbackFilterIterator::__construct(): Argument #2 ($callback) must be a valid callback, array must have exactly two members
some message
2 changes: 1 addition & 1 deletion ext/spl/tests/arrayObject___construct_error2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ try {
?>
--EXPECT--
Too many arguments:
ArrayObject::__construct() expects at most 3 parameters, 4 given(12)
ArrayObject::__construct(): At most 3 arguments are expected, 4 given(12)
2 changes: 1 addition & 1 deletion ext/spl/tests/arrayObject_exchangeArray_basic3.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ array(2) {


--> exchangeArray() with no arg:
Exception: ArrayObject::exchangeArray() expects exactly 1 parameter, 0 given
Exception: ArrayObject::exchangeArray(): Exactly 1 argument is expected, 0 given

Warning: Undefined variable $copy in %s on line %d
object(ArrayObject)#2 (1) {
Expand Down
4 changes: 2 additions & 2 deletions ext/spl/tests/arrayObject_uasort_error1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ try {
}
?>
--EXPECT--
ArrayObject::uasort() expects exactly 1 parameter, 0 given
ArrayObject::uasort() expects exactly 1 parameter, 2 given
ArrayObject::uasort(): Exactly 1 argument is expected, 0 given
ArrayObject::uasort(): Exactly 1 argument is expected, 2 given
4 changes: 2 additions & 2 deletions ext/spl/tests/arrayObject_uksort_error1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ try {
}
?>
--EXPECT--
ArrayObject::uksort() expects exactly 1 parameter, 0 given
ArrayObject::uksort() expects exactly 1 parameter, 2 given
ArrayObject::uksort(): Exactly 1 argument is expected, 0 given
ArrayObject::uksort(): Exactly 1 argument is expected, 2 given
12 changes: 6 additions & 6 deletions ext/spl/tests/iterator_056.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ try {

?>
--EXPECT--
FilterIterator::__construct() expects exactly 1 parameter, 0 given
CachingIterator::__construct() expects at least 1 parameter, 0 given
RecursiveCachingIterator::__construct() expects at least 1 parameter, 0 given
ParentIterator::__construct() expects exactly 1 parameter, 0 given
LimitIterator::__construct() expects at least 1 parameter, 0 given
NoRewindIterator::__construct() expects exactly 1 parameter, 0 given
FilterIterator::__construct(): Exactly 1 argument is expected, 0 given
CachingIterator::__construct(): At least 1 argument is expected, 0 given
RecursiveCachingIterator::__construct(): At least 1 argument is expected, 0 given
ParentIterator::__construct(): Exactly 1 argument is expected, 0 given
LimitIterator::__construct(): At least 1 argument is expected, 0 given
NoRewindIterator::__construct(): Exactly 1 argument is expected, 0 given
2 changes: 1 addition & 1 deletion ext/spl/tests/iterator_062.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ try {
}
?>
--EXPECT--
RecursiveIteratorIterator::__construct() expects at least 1 parameter, 0 given
RecursiveIteratorIterator::__construct(): At least 1 argument is expected, 0 given
2 changes: 1 addition & 1 deletion ext/spl/tests/recursive_tree_iterator_002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ try {
}
?>
--EXPECT--
RecursiveTreeIterator::__construct() expects at least 1 parameter, 0 given
RecursiveTreeIterator::__construct(): At least 1 argument is expected, 0 given
2 changes: 1 addition & 1 deletion ext/spl/tests/spl_004.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,4 @@ int(4)
===ERRORS===
iterator_apply(): Argument #3 ($args) must be of type ?array, int given
iterator_apply(): Argument #2 ($function) must be a valid callback, function "non_existing_function" not found or invalid function name
iterator_apply() expects at most 3 parameters, 4 given
iterator_apply(): At most 3 arguments are expected, 4 given
2 changes: 1 addition & 1 deletion ext/spl/tests/spl_iterator_iterator_constructor.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ try {

?>
--EXPECT--
IteratorIterator::__construct() expects at most 2 parameters, 3 given
IteratorIterator::__construct(): At most 2 arguments are expected, 3 given
2 changes: 1 addition & 1 deletion ext/standard/tests/array/array_filter_variation10.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,5 @@ array(2) {
["b"]=>
int(2)
}
is_numeric() expects exactly 1 parameter, 2 given
is_numeric(): Exactly 1 argument is expected, 2 given
Done
2 changes: 1 addition & 1 deletion ext/standard/tests/array/array_map_error.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ echo "Done";
*** Testing array_map() : error conditions ***

-- Testing array_map() function with one less than expected no. of arguments --
Exception: array_map() expects at least 2 parameters, 1 given
Exception: array_map(): At least 2 arguments are expected, 1 given

-- Testing array_map() function with less no. of arrays than callback function arguments --
Exception: Too few arguments to function callback2(), 1 passed and exactly 2 expected
Expand Down
2 changes: 1 addition & 1 deletion ext/standard/tests/array/array_map_variation12.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ array(3) {
int(243)
}
-- with built-in function 'pow' and one parameter --
pow() expects exactly 2 parameters, 1 given
pow(): Exactly 2 arguments are expected, 1 given
-- with language construct --
array_map(): Argument #1 ($callback) must be a valid callback, function "echo" not found or invalid function name
Done
2 changes: 1 addition & 1 deletion ext/standard/tests/array/array_walk_error2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@ Exception: Too few arguments to function callback2(), 3 passed and exactly 4 exp
Exception: Too few arguments to function callback1(), 2 passed and exactly 3 expected
Exception: Too few arguments to function callback2(), 3 passed and exactly 4 expected
-- Testing array_walk() function with too many callback parameters --
Exception: array_walk() expects at most 3 parameters, 4 given
Exception: array_walk(): At most 3 arguments are expected, 4 given
Done
2 changes: 1 addition & 1 deletion ext/standard/tests/array/array_walk_recursive_error2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@ Exception: Too few arguments to function callback2(), 3 passed and exactly 4 exp
Exception: Too few arguments to function callback1(), 2 passed and exactly 3 expected
Exception: Too few arguments to function callback2(), 3 passed and exactly 4 expected
-- Testing array_walk_recursive() function with too many callback parameters --
Exception: array_walk_recursive() expects at most 3 parameters, 4 given
Exception: array_walk_recursive(): At most 3 arguments are expected, 4 given
Done
2 changes: 1 addition & 1 deletion ext/standard/tests/password/password_hash_error.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ try {

?>
--EXPECTF--
password_hash() expects at least 2 parameters, 1 given
password_hash(): At least 2 arguments are expected, 1 given

Warning: Array to string conversion in %s on line %d
password_hash(): Argument #2 ($algo) must be a valid password hashing algorithm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ try {
echo "OK!";
?>
--EXPECT--
password_needs_rehash() expects at least 2 parameters, 1 given
password_needs_rehash(): At least 2 arguments are expected, 1 given
bool(false)
password_needs_rehash(): Argument #1 ($hash) must be of type string, array given
password_needs_rehash(): Argument #3 ($options) must be of type array, string given
Expand Down
2 changes: 1 addition & 1 deletion ext/standard/tests/password/password_verify_error.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ try {

?>
--EXPECT--
password_verify() expects exactly 2 parameters, 1 given
password_verify(): Exactly 2 arguments are expected, 1 given
2 changes: 1 addition & 1 deletion ext/standard/tests/random/random_bytes_error.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ try {

?>
--EXPECT--
random_bytes() expects exactly 1 parameter, 0 given
random_bytes(): Exactly 1 argument is expected, 0 given
random_bytes(): Argument #1 ($length) must be greater than 0
4 changes: 2 additions & 2 deletions ext/standard/tests/random/random_int_error.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ try {

?>
--EXPECT--
random_int() expects exactly 2 parameters, 0 given
random_int() expects exactly 2 parameters, 1 given
random_int(): Exactly 2 arguments are expected, 0 given
random_int(): Exactly 2 arguments are expected, 1 given
random_int(): Argument #1 ($min) must be less than or equal to argument #2 ($max)
4 changes: 2 additions & 2 deletions ext/standard/tests/strings/chr_error.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ try {
*** Testing chr() : error conditions ***

-- Testing chr() function with no arguments --
chr() expects exactly 1 parameter, 0 given
chr(): Exactly 1 argument is expected, 0 given

-- Testing chr() function with more than expected no. of arguments --
chr() expects exactly 1 parameter, 2 given
chr(): Exactly 1 argument is expected, 2 given
6 changes: 3 additions & 3 deletions ext/standard/tests/strings/fprintf_error.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ echo "Done\n";
?>
--EXPECT--
*** Testing Error Conditions ***
fprintf() expects at least 2 parameters, 0 given
fprintf() expects at least 2 parameters, 1 given
fprintf() expects at least 2 parameters, 1 given
fprintf(): At least 2 arguments are expected, 0 given
fprintf(): At least 2 arguments are expected, 1 given
fprintf(): At least 2 arguments are expected, 1 given
Done
2 changes: 1 addition & 1 deletion ext/standard/tests/strings/printf_64bit.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ printf("%d", $tempstring);
?>
--EXPECTF--
*** Output for zero argument ***
printf() expects at least 1 parameter, 0 given
printf(): At least 1 argument is expected, 0 given

*** Output for insufficient number of arguments ***
Error found: 5 parameters are required, 3 given
Expand Down
2 changes: 1 addition & 1 deletion ext/standard/tests/strings/printf_error.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ try {
*** Testing printf() : error conditions ***

-- Testing printf() function with Zero arguments --
printf() expects at least 1 parameter, 0 given
printf(): At least 1 argument is expected, 0 given

-- Testing printf() function with less than expected no. of arguments --

Expand Down
4 changes: 2 additions & 2 deletions ext/standard/tests/strings/sprintf_error.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ try {

echo "Done";
?>
--EXPECTF--
--EXPECT--
*** Testing sprintf() : error conditions ***

-- Testing sprintf() function with Zero arguments --
sprintf() expects at least %d parameter, %d given
sprintf(): At least 1 argument is expected, 0 given

-- Testing sprintf() function with less than expected no. of arguments --
2 parameters are required, 1 given
Expand Down
4 changes: 2 additions & 2 deletions ext/standard/tests/strings/vfprintf_error1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ unlink( $file );
?>
--EXPECT--
-- Testing vfprintf() function with more than expected no. of arguments --
vfprintf() expects exactly 3 parameters, 4 given
vfprintf() expects exactly 3 parameters, 4 given
vfprintf(): Exactly 3 arguments are expected, 4 given
vfprintf(): Exactly 3 arguments are expected, 4 given
2 changes: 1 addition & 1 deletion tests/output/ob_014.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ try {
?>
--EXPECT--
foo
str_rot13() expects exactly 1 parameter, 2 given
str_rot13(): Exactly 1 argument is expected, 2 given
2 changes: 1 addition & 1 deletion tests/output/ob_015.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ ob_end_flush();
?>
--EXPECT--
foo
str_rot13() expects exactly 1 parameter, 2 given
str_rot13(): Exactly 1 argument is expected, 2 given

0 comments on commit c0422ce

Please sign in to comment.