Skip to content

Commit c0422ce

Browse files
committed
Improve ArgumentCountError error message
1 parent 14740f7 commit c0422ce

36 files changed

+70
-70
lines changed

Zend/tests/bug46106.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ try {
2323
?>
2424
DONE
2525
--EXPECT--
26-
str_pad() expects at least 2 parameters, 1 given
26+
str_pad(): At least 2 arguments are expected, 1 given
2727
DONE

Zend/tests/bug51827.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ register_shutdown_function('exploDe');
1616
--EXPECT--
1717
int(1)
1818

19-
Fatal error: Uncaught ArgumentCountError: explode() expects at least 2 parameters, 0 given in [no active file]:0
19+
Fatal error: Uncaught ArgumentCountError: explode(): At least 2 arguments are expected, 0 given in [no active file]:0
2020
Stack trace:
2121
#0 [internal function]: explode()
2222
#1 {main}

Zend/tests/function_arguments/argument_count_incorrect_internal.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ try {
99
}
1010
?>
1111
--EXPECT--
12-
substr() expects at least 2 parameters, 1 given
12+
substr(): At least 2 arguments are expected, 1 given

Zend/tests/function_arguments/argument_count_incorrect_internal_strict.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ try {
1919
?>
2020
--EXPECT--
2121
ArgumentCountError
22-
substr() expects at least 2 parameters, 1 given
22+
substr(): At least 2 arguments are expected, 1 given
2323
ArgumentCountError
2424
At least 2 parameters are required, 1 given

Zend/zend_API.c

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -198,18 +198,18 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameters_none_error(void) /*
198198
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameters_count_error(uint32_t min_num_args, uint32_t max_num_args) /* {{{ */
199199
{
200200
uint32_t num_args = ZEND_CALL_NUM_ARGS(EG(current_execute_data));
201-
zend_function *active_function = EG(current_execute_data)->func;
202-
const char *class_name = active_function->common.scope ? ZSTR_VAL(active_function->common.scope->name) : "";
201+
char *func_name = get_active_function_or_method_name();
203202

204203
zend_argument_count_error(
205-
"%s%s%s() expects %s %d parameter%s, %d given",
206-
class_name, \
207-
class_name[0] ? "::" : "", \
208-
ZSTR_VAL(active_function->common.function_name),
209-
min_num_args == max_num_args ? "exactly" : num_args < min_num_args ? "at least" : "at most",
210-
num_args < min_num_args ? min_num_args : max_num_args,
211-
(num_args < min_num_args ? min_num_args : max_num_args) == 1 ? "" : "s",
212-
num_args);
204+
"%s(): %s %d argument%s %s expected, %d given",
205+
func_name, min_num_args == max_num_args ? "Exactly" : num_args < min_num_args ? "At least" : "At most",
206+
num_args < min_num_args ? min_num_args : max_num_args,
207+
(num_args < min_num_args ? min_num_args : max_num_args) == 1 ? "" : "s",
208+
(num_args < min_num_args ? min_num_args : max_num_args) == 1 ? "is" : "are",
209+
num_args
210+
);
211+
212+
efree(func_name);
213213
}
214214
/* }}} */
215215

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

988988
if (num_args < min_num_args || num_args > max_num_args) {
989989
if (!(flags & ZEND_PARSE_PARAMS_QUIET)) {
990-
zend_function *active_function = EG(current_execute_data)->func;
991-
const char *class_name = active_function->common.scope ? ZSTR_VAL(active_function->common.scope->name) : "";
992-
zend_argument_count_error("%s%s%s() expects %s %d parameter%s, %d given",
993-
class_name,
994-
class_name[0] ? "::" : "",
995-
ZSTR_VAL(active_function->common.function_name),
996-
min_num_args == max_num_args ? "exactly" : num_args < min_num_args ? "at least" : "at most",
997-
num_args < min_num_args ? min_num_args : max_num_args,
998-
(num_args < min_num_args ? min_num_args : max_num_args) == 1 ? "" : "s",
999-
num_args);
990+
char *func_name = get_active_function_or_method_name();
991+
zend_argument_count_error("%s(): %s %d argument%s %s expected, %d given",
992+
func_name, min_num_args == max_num_args ? "Exactly" : num_args < min_num_args ? "At least" : "At most",
993+
num_args < min_num_args ? min_num_args : max_num_args,
994+
(num_args < min_num_args ? min_num_args : max_num_args) == 1 ? "" : "s",
995+
(num_args < min_num_args ? min_num_args : max_num_args) == 1 ? "is" : "are",
996+
num_args
997+
);
998+
999+
efree(func_name);
10001000
}
10011001
return FAILURE;
10021002
}

ext/date/tests/DateTimeZone_construct_error.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ try {
2121
*** Testing DateTimeZone() : error conditions ***
2222

2323
-- Testing new DateTimeZone() with more than expected no. of arguments --
24-
DateTimeZone::__construct() expects exactly 1 parameter, 2 given
24+
DateTimeZone::__construct(): Exactly 1 argument is expected, 2 given

ext/date/tests/DateTime_construct_error.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ try {
2222
*** Testing date_create() : error conditions ***
2323

2424
-- Testing new DateTime() with more than expected no. of arguments --
25-
DateTime::__construct() expects at most 2 parameters, 3 given
25+
DateTime::__construct(): At most 2 arguments are expected, 3 given

ext/date/tests/mktime_error.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ try {
3333
*** Testing mktime() : error conditions ***
3434

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

3838
-- Testing mktime() function with more than expected no. of arguments --
39-
mktime() expects at most 6 parameters, 7 given
39+
mktime(): At most 6 arguments are expected, 7 given

ext/spl/tests/CallbackFilterIteratorTest-002.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ try {
4242
}
4343
?>
4444
--EXPECT--
45-
CallbackFilterIterator::__construct() expects exactly 2 parameters, 0 given
46-
CallbackFilterIterator::__construct() expects exactly 2 parameters, 1 given
45+
CallbackFilterIterator::__construct(): Exactly 2 arguments are expected, 0 given
46+
CallbackFilterIterator::__construct(): Exactly 2 arguments are expected, 1 given
4747
CallbackFilterIterator::__construct(): Argument #2 ($callback) must be a valid callback, no array or string given
4848
CallbackFilterIterator::__construct(): Argument #2 ($callback) must be a valid callback, array must have exactly two members
4949
some message

ext/spl/tests/arrayObject___construct_error2.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ try {
1919
?>
2020
--EXPECT--
2121
Too many arguments:
22-
ArrayObject::__construct() expects at most 3 parameters, 4 given(12)
22+
ArrayObject::__construct(): At most 3 arguments are expected, 4 given(12)

ext/spl/tests/arrayObject_exchangeArray_basic3.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ array(2) {
8181

8282

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

8686
Warning: Undefined variable $copy in %s on line %d
8787
object(ArrayObject)#2 (1) {

ext/spl/tests/arrayObject_uasort_error1.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ try {
2222
}
2323
?>
2424
--EXPECT--
25-
ArrayObject::uasort() expects exactly 1 parameter, 0 given
26-
ArrayObject::uasort() expects exactly 1 parameter, 2 given
25+
ArrayObject::uasort(): Exactly 1 argument is expected, 0 given
26+
ArrayObject::uasort(): Exactly 1 argument is expected, 2 given

ext/spl/tests/arrayObject_uksort_error1.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ try {
2222
}
2323
?>
2424
--EXPECT--
25-
ArrayObject::uksort() expects exactly 1 parameter, 0 given
26-
ArrayObject::uksort() expects exactly 1 parameter, 2 given
25+
ArrayObject::uksort(): Exactly 1 argument is expected, 0 given
26+
ArrayObject::uksort(): Exactly 1 argument is expected, 2 given

ext/spl/tests/iterator_056.phpt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ try {
5656

5757
?>
5858
--EXPECT--
59-
FilterIterator::__construct() expects exactly 1 parameter, 0 given
60-
CachingIterator::__construct() expects at least 1 parameter, 0 given
61-
RecursiveCachingIterator::__construct() expects at least 1 parameter, 0 given
62-
ParentIterator::__construct() expects exactly 1 parameter, 0 given
63-
LimitIterator::__construct() expects at least 1 parameter, 0 given
64-
NoRewindIterator::__construct() expects exactly 1 parameter, 0 given
59+
FilterIterator::__construct(): Exactly 1 argument is expected, 0 given
60+
CachingIterator::__construct(): At least 1 argument is expected, 0 given
61+
RecursiveCachingIterator::__construct(): At least 1 argument is expected, 0 given
62+
ParentIterator::__construct(): Exactly 1 argument is expected, 0 given
63+
LimitIterator::__construct(): At least 1 argument is expected, 0 given
64+
NoRewindIterator::__construct(): Exactly 1 argument is expected, 0 given

ext/spl/tests/iterator_062.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ try {
1515
}
1616
?>
1717
--EXPECT--
18-
RecursiveIteratorIterator::__construct() expects at least 1 parameter, 0 given
18+
RecursiveIteratorIterator::__construct(): At least 1 argument is expected, 0 given

ext/spl/tests/recursive_tree_iterator_002.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ try {
1111
}
1212
?>
1313
--EXPECT--
14-
RecursiveTreeIterator::__construct() expects at least 1 parameter, 0 given
14+
RecursiveTreeIterator::__construct(): At least 1 argument is expected, 0 given

ext/spl/tests/spl_004.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,4 @@ int(4)
8686
===ERRORS===
8787
iterator_apply(): Argument #3 ($args) must be of type ?array, int given
8888
iterator_apply(): Argument #2 ($function) must be a valid callback, function "non_existing_function" not found or invalid function name
89-
iterator_apply() expects at most 3 parameters, 4 given
89+
iterator_apply(): At most 3 arguments are expected, 4 given

ext/spl/tests/spl_iterator_iterator_constructor.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ try {
2121

2222
?>
2323
--EXPECT--
24-
IteratorIterator::__construct() expects at most 2 parameters, 3 given
24+
IteratorIterator::__construct(): At most 2 arguments are expected, 3 given

ext/standard/tests/array/array_filter_variation10.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,5 @@ array(2) {
8787
["b"]=>
8888
int(2)
8989
}
90-
is_numeric() expects exactly 1 parameter, 2 given
90+
is_numeric(): Exactly 1 argument is expected, 2 given
9191
Done

ext/standard/tests/array/array_map_error.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ echo "Done";
3737
*** Testing array_map() : error conditions ***
3838

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

4242
-- Testing array_map() function with less no. of arrays than callback function arguments --
4343
Exception: Too few arguments to function callback2(), 1 passed and exactly 2 expected

ext/standard/tests/array/array_map_variation12.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ array(3) {
4242
int(243)
4343
}
4444
-- with built-in function 'pow' and one parameter --
45-
pow() expects exactly 2 parameters, 1 given
45+
pow(): Exactly 2 arguments are expected, 1 given
4646
-- with language construct --
4747
array_map(): Argument #1 ($callback) must be a valid callback, function "echo" not found or invalid function name
4848
Done

ext/standard/tests/array/array_walk_error2.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,5 @@ Exception: Too few arguments to function callback2(), 3 passed and exactly 4 exp
5656
Exception: Too few arguments to function callback1(), 2 passed and exactly 3 expected
5757
Exception: Too few arguments to function callback2(), 3 passed and exactly 4 expected
5858
-- Testing array_walk() function with too many callback parameters --
59-
Exception: array_walk() expects at most 3 parameters, 4 given
59+
Exception: array_walk(): At most 3 arguments are expected, 4 given
6060
Done

ext/standard/tests/array/array_walk_recursive_error2.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,5 @@ Exception: Too few arguments to function callback2(), 3 passed and exactly 4 exp
5656
Exception: Too few arguments to function callback1(), 2 passed and exactly 3 expected
5757
Exception: Too few arguments to function callback2(), 3 passed and exactly 4 expected
5858
-- Testing array_walk_recursive() function with too many callback parameters --
59-
Exception: array_walk_recursive() expects at most 3 parameters, 4 given
59+
Exception: array_walk_recursive(): At most 3 arguments are expected, 4 given
6060
Done

ext/standard/tests/password/password_hash_error.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ try {
3636

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

4141
Warning: Array to string conversion in %s on line %d
4242
password_hash(): Argument #2 ($algo) must be a valid password hashing algorithm

ext/standard/tests/password/password_needs_rehash_error.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ try {
2727
echo "OK!";
2828
?>
2929
--EXPECT--
30-
password_needs_rehash() expects at least 2 parameters, 1 given
30+
password_needs_rehash(): At least 2 arguments are expected, 1 given
3131
bool(false)
3232
password_needs_rehash(): Argument #1 ($hash) must be of type string, array given
3333
password_needs_rehash(): Argument #3 ($options) must be of type array, string given

ext/standard/tests/password/password_verify_error.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ try {
1212

1313
?>
1414
--EXPECT--
15-
password_verify() expects exactly 2 parameters, 1 given
15+
password_verify(): Exactly 2 arguments are expected, 1 given

ext/standard/tests/random/random_bytes_error.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ try {
1818

1919
?>
2020
--EXPECT--
21-
random_bytes() expects exactly 1 parameter, 0 given
21+
random_bytes(): Exactly 1 argument is expected, 0 given
2222
random_bytes(): Argument #1 ($length) must be greater than 0

ext/standard/tests/random/random_int_error.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ try {
2424

2525
?>
2626
--EXPECT--
27-
random_int() expects exactly 2 parameters, 0 given
28-
random_int() expects exactly 2 parameters, 1 given
27+
random_int(): Exactly 2 arguments are expected, 0 given
28+
random_int(): Exactly 2 arguments are expected, 1 given
2929
random_int(): Argument #1 ($min) must be less than or equal to argument #2 ($max)

ext/standard/tests/strings/chr_error.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ try {
2525
*** Testing chr() : error conditions ***
2626

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

3030
-- Testing chr() function with more than expected no. of arguments --
31-
chr() expects exactly 1 parameter, 2 given
31+
chr(): Exactly 1 argument is expected, 2 given

ext/standard/tests/strings/fprintf_error.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ echo "Done\n";
3131
?>
3232
--EXPECT--
3333
*** Testing Error Conditions ***
34-
fprintf() expects at least 2 parameters, 0 given
35-
fprintf() expects at least 2 parameters, 1 given
36-
fprintf() expects at least 2 parameters, 1 given
34+
fprintf(): At least 2 arguments are expected, 0 given
35+
fprintf(): At least 2 arguments are expected, 1 given
36+
fprintf(): At least 2 arguments are expected, 1 given
3737
Done

ext/standard/tests/strings/printf_64bit.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ printf("%d", $tempstring);
238238
?>
239239
--EXPECTF--
240240
*** Output for zero argument ***
241-
printf() expects at least 1 parameter, 0 given
241+
printf(): At least 1 argument is expected, 0 given
242242

243243
*** Output for insufficient number of arguments ***
244244
Error found: 5 parameters are required, 3 given

ext/standard/tests/strings/printf_error.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ try {
6060
*** Testing printf() : error conditions ***
6161

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

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

ext/standard/tests/strings/sprintf_error.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ try {
6969

7070
echo "Done";
7171
?>
72-
--EXPECTF--
72+
--EXPECT--
7373
*** Testing sprintf() : error conditions ***
7474

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

7878
-- Testing sprintf() function with less than expected no. of arguments --
7979
2 parameters are required, 1 given

ext/standard/tests/strings/vfprintf_error1.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,5 @@ unlink( $file );
3838
?>
3939
--EXPECT--
4040
-- Testing vfprintf() function with more than expected no. of arguments --
41-
vfprintf() expects exactly 3 parameters, 4 given
42-
vfprintf() expects exactly 3 parameters, 4 given
41+
vfprintf(): Exactly 3 arguments are expected, 4 given
42+
vfprintf(): Exactly 3 arguments are expected, 4 given

tests/output/ob_014.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ try {
1212
?>
1313
--EXPECT--
1414
foo
15-
str_rot13() expects exactly 1 parameter, 2 given
15+
str_rot13(): Exactly 1 argument is expected, 2 given

tests/output/ob_015.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ ob_end_flush();
1212
?>
1313
--EXPECT--
1414
foo
15-
str_rot13() expects exactly 1 parameter, 2 given
15+
str_rot13(): Exactly 1 argument is expected, 2 given

0 commit comments

Comments
 (0)