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 17, 2020
1 parent 06966fe commit 0257580
Show file tree
Hide file tree
Showing 78 changed files with 156 additions and 156 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
2 changes: 1 addition & 1 deletion ext/dom/tests/DOMAttr_construct_error_001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ try {
}
?>
--EXPECT--
DOMAttr::__construct() expects at least 1 parameter, 0 given
DOMAttr::__construct(): At least 1 argument is expected, 0 given
2 changes: 1 addition & 1 deletion ext/dom/tests/DOMCDATASection_construct_error_001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ Nic Rosental [email protected]
}
?>
--EXPECT--
DOMCdataSection::__construct() expects exactly 1 parameter, 0 given
DOMCdataSection::__construct(): Exactly 1 argument is expected, 0 given
2 changes: 1 addition & 1 deletion ext/dom/tests/DOMComment_construct_error_001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ try {
}
?>
--EXPECT--
DOMComment::__construct() expects at most 1 parameter, 2 given
DOMComment::__construct(): At most 1 argument is expected, 2 given
2 changes: 1 addition & 1 deletion ext/fileinfo/tests/bug61173.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ try {
}
?>
--EXPECT--
finfo::__construct() expects at most 2 parameters, 3 given
finfo::__construct(): At most 2 arguments are expected, 3 given
4 changes: 2 additions & 2 deletions ext/intl/tests/breakiter___construct_error.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ try {
--EXPECTF--
Exception: IntlRuleBasedBreakIterator::__construct(): rbbi_create_instance: unable to create RuleBasedBreakIterator from rules (parse error on line 1, offset 31) in %s on line %d

Exception: IntlRuleBasedBreakIterator::__construct() expects at least 1 parameter, 0 given in %s on line %d
Exception: IntlRuleBasedBreakIterator::__construct(): At least 1 argument is expected, 0 given in %s on line %d

Exception: IntlRuleBasedBreakIterator::__construct() expects at most 2 parameters, 3 given in %s on line %d
Exception: IntlRuleBasedBreakIterator::__construct(): At most 2 arguments are expected, 3 given in %s on line %d

Exception: IntlRuleBasedBreakIterator::__construct(): Argument #2 ($areCompiled) must be of type bool, array given in %s on line %d

Expand Down
12 changes: 6 additions & 6 deletions ext/intl/tests/calendar_before_after_error.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,18 @@ try {
}
?>
--EXPECT--
error: 0, IntlCalendar::after() expects exactly 1 parameter, 0 given
error: 0, IntlCalendar::after(): Exactly 1 argument is expected, 0 given

error: 0, IntlCalendar::before() expects exactly 1 parameter, 0 given
error: 0, IntlCalendar::before(): Exactly 1 argument is expected, 0 given

error: 0, IntlCalendar::after(): Argument #1 ($calendar) must be of type IntlCalendar, int given

error: 0, IntlCalendar::before(): Argument #1 ($calendar) must be of type IntlCalendar, int given

error: 0, IntlCalendar::after() expects exactly 1 parameter, 2 given
error: 0, IntlCalendar::after(): Exactly 1 argument is expected, 2 given

error: 0, IntlCalendar::before() expects exactly 1 parameter, 2 given
error: 0, IntlCalendar::before(): Exactly 1 argument is expected, 2 given

error: 0, intlcal_after() expects exactly 2 parameters, 1 given
error: 0, intlcal_after(): Exactly 2 arguments are expected, 1 given

error: 0, intlcal_before() expects exactly 2 parameters, 1 given
error: 0, intlcal_before(): Exactly 2 arguments are expected, 1 given
4 changes: 2 additions & 2 deletions ext/intl/tests/calendar_equals_error.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ try {
}
?>
--EXPECT--
error: 0, IntlCalendar::equals() expects exactly 1 parameter, 0 given
error: 0, IntlCalendar::equals(): Exactly 1 argument is expected, 0 given

error: 0, IntlCalendar::equals(): Argument #1 ($calendar) must be of type IntlCalendar, stdClass given

error: 0, IntlCalendar::equals() expects exactly 1 parameter, 2 given
error: 0, IntlCalendar::equals(): Exactly 1 argument is expected, 2 given

error: 0, intlcal_equals(): Argument #2 ($calendar) must be of type IntlCalendar, array given

Expand Down
4 changes: 2 additions & 2 deletions ext/intl/tests/calendar_fieldDifference_error.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ try {
var_dump(intlcal_field_difference(1, 0, 1));
?>
--EXPECTF--
IntlCalendar::fieldDifference() expects exactly 2 parameters, 3 given
IntlCalendar::fieldDifference(): Exactly 2 arguments are expected, 3 given

Warning: IntlCalendar::fieldDifference(): intlcal_field_difference: Call to ICU method has failed in %s on line %d
bool(false)
intlcal_field_difference() expects exactly 3 parameters, 4 given
intlcal_field_difference(): Exactly 3 arguments are expected, 4 given

Fatal error: Uncaught TypeError: intlcal_field_difference(): Argument #1 ($calendar) must be of type IntlCalendar, int given in %s:%d
Stack trace:
Expand Down
2 changes: 1 addition & 1 deletion ext/intl/tests/calendar_getLocale_error.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ini_set("intl.error_level", E_WARNING);
var_dump(intlcal_get_locale(1));
?>
--EXPECTF--
Fatal error: Uncaught ArgumentCountError: intlcal_get_locale() expects exactly 2 parameters, 1 given in %s:%d
Fatal error: Uncaught ArgumentCountError: intlcal_get_locale(): Exactly 2 arguments are expected, 1 given in %s:%d
Stack trace:
#0 %s(%d): intlcal_get_locale(1)
#1 {main}
Expand Down
12 changes: 6 additions & 6 deletions ext/intl/tests/calendar_get_getActualMaximum_Minumum_error2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ try {
}
?>
--EXPECT--
ArgumentCountError: 0, intlcal_get() expects exactly 2 parameters, 1 given
ArgumentCountError: 0, intlcal_get_actual_maximum() expects exactly 2 parameters, 1 given
ArgumentCountError: 0, intlcal_get_actual_minimum() expects exactly 2 parameters, 1 given
ArgumentCountError: 0, intlcal_get(): Exactly 2 arguments are expected, 1 given
ArgumentCountError: 0, intlcal_get_actual_maximum(): Exactly 2 arguments are expected, 1 given
ArgumentCountError: 0, intlcal_get_actual_minimum(): Exactly 2 arguments are expected, 1 given
ValueError: 0, intlcal_get(): Argument #2 ($field) must be a valid field
ValueError: 0, intlcal_get_actual_maximum(): Argument #2 ($field) must be a valid field
ValueError: 0, intlcal_get_actual_minimum(): Argument #2 ($field) must be a valid field
TypeError: 0, intlcal_get(): Argument #2 ($field) must be of type int, string given
TypeError: 0, intlcal_get_actual_maximum(): Argument #2 ($field) must be of type int, string given
TypeError: 0, intlcal_get_actual_minimum(): Argument #2 ($field) must be of type int, string given
ArgumentCountError: 0, intlcal_get() expects exactly 2 parameters, 1 given
ArgumentCountError: 0, intlcal_get_actual_maximum() expects exactly 2 parameters, 1 given
ArgumentCountError: 0, intlcal_get_actual_minimum() expects exactly 2 parameters, 1 given
ArgumentCountError: 0, intlcal_get(): Exactly 2 arguments are expected, 1 given
ArgumentCountError: 0, intlcal_get_actual_maximum(): Exactly 2 arguments are expected, 1 given
ArgumentCountError: 0, intlcal_get_actual_minimum(): Exactly 2 arguments are expected, 1 given
4 changes: 2 additions & 2 deletions ext/intl/tests/calendar_isEquivalentTo_error.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ try {
--EXPECT--
error: 0, IntlCalendar::isEquivalentTo(): Argument #1 ($calendar) must be of type IntlCalendar, int given

error: 0, IntlCalendar::isEquivalentTo() expects exactly 1 parameter, 2 given
error: 0, IntlCalendar::isEquivalentTo(): Exactly 1 argument is expected, 2 given

error: 0, IntlCalendar::isEquivalentTo(): Argument #1 ($calendar) must be of type IntlCalendar, int given

error: 0, intlcal_is_equivalent_to() expects exactly 2 parameters, 1 given
error: 0, intlcal_is_equivalent_to(): Exactly 2 arguments are expected, 1 given

error: 0, intlcal_is_equivalent_to(): Argument #2 ($calendar) must be of type IntlCalendar, int given

Expand Down
6 changes: 3 additions & 3 deletions ext/intl/tests/calendar_setTimeZone_error.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ try{
}
?>
--EXPECT--
error: 0, IntlCalendar::setTimeZone() expects exactly 1 parameter, 2 given
error: 0, IntlCalendar::setTimeZone(): Exactly 1 argument is expected, 2 given

error: 0, IntlCalendar::setTimeZone() expects exactly 1 parameter, 0 given
error: 0, IntlCalendar::setTimeZone(): Exactly 1 argument is expected, 0 given

error: 0, intlcal_set_time_zone() expects exactly 2 parameters, 3 given
error: 0, intlcal_set_time_zone(): Exactly 2 arguments are expected, 3 given

error: 0, intlcal_set_time_zone(): Argument #1 ($calendar) must be of type IntlCalendar, int given
2 changes: 1 addition & 1 deletion ext/intl/tests/calendar_setTime_error.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ini_set("intl.error_level", E_WARNING);
var_dump(intlcal_set_time(1));
?>
--EXPECTF--
Fatal error: Uncaught ArgumentCountError: intlcal_set_time() expects exactly 2 parameters, 1 given in %s:%d
Fatal error: Uncaught ArgumentCountError: intlcal_set_time(): Exactly 2 arguments are expected, 1 given in %s:%d
Stack trace:
#0 %s(%d): intlcal_set_time(1)
#1 {main}
Expand Down
2 changes: 1 addition & 1 deletion ext/intl/tests/calendar_set_error.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ try {
}
?>
--EXPECT--
IntlCalendar::set() expects at most 6 parameters, 7 given
IntlCalendar::set(): At most 6 arguments are expected, 7 given
IntlCalendar::set() has no variant with exactly 4 parameters
IntlCalendar::set(): Argument #1 ($year) must be a valid field
intlcal_set(): Argument #2 ($year) must be a valid field
Expand Down
6 changes: 3 additions & 3 deletions ext/intl/tests/formatter_fail.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@ foreach($args as $arg) {

?>
--EXPECTF--
ArgumentCountError: NumberFormatter::__construct() expects at least 2 parameters, 0 given in %s on line %d
ArgumentCountError: NumberFormatter::__construct(): At least 2 arguments are expected, 0 given in %s on line %d
'U_ZERO_ERROR'

ArgumentCountError: numfmt_create() expects at least 2 parameters, 0 given in %s on line %d
ArgumentCountError: numfmt_create(): At least 2 arguments are expected, 0 given in %s on line %d
'U_ZERO_ERROR'

ArgumentCountError: NumberFormatter::create() expects at least 2 parameters, 0 given in %s on line %d
ArgumentCountError: NumberFormatter::create(): At least 2 arguments are expected, 0 given in %s on line %d
'U_ZERO_ERROR'

IntlException: Constructor failed in %s on line %d
Expand Down
12 changes: 6 additions & 6 deletions ext/intl/tests/msgfmt_fail2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -108,22 +108,22 @@ foreach($args as $arg) {

?>
--EXPECTF--
ArgumentCountError: MessageFormatter::__construct() expects exactly 2 parameters, 0 given in %s on line %d
ArgumentCountError: MessageFormatter::__construct(): Exactly 2 arguments are expected, 0 given in %s on line %d
'U_ZERO_ERROR'

ArgumentCountError: msgfmt_create() expects exactly 2 parameters, 0 given in %s on line %d
ArgumentCountError: msgfmt_create(): Exactly 2 arguments are expected, 0 given in %s on line %d
'U_ZERO_ERROR'

ArgumentCountError: MessageFormatter::create() expects exactly 2 parameters, 0 given in %s on line %d
ArgumentCountError: MessageFormatter::create(): Exactly 2 arguments are expected, 0 given in %s on line %d
'U_ZERO_ERROR'

ArgumentCountError: MessageFormatter::__construct() expects exactly 2 parameters, 1 given in %s on line %d
ArgumentCountError: MessageFormatter::__construct(): Exactly 2 arguments are expected, 1 given in %s on line %d
'U_ZERO_ERROR'

ArgumentCountError: msgfmt_create() expects exactly 2 parameters, 1 given in %s on line %d
ArgumentCountError: msgfmt_create(): Exactly 2 arguments are expected, 1 given in %s on line %d
'U_ZERO_ERROR'

ArgumentCountError: MessageFormatter::create() expects exactly 2 parameters, 1 given in %s on line %d
ArgumentCountError: MessageFormatter::create(): Exactly 2 arguments are expected, 1 given in %s on line %d
'U_ZERO_ERROR'

IntlException: Constructor failed in %s on line %d
Expand Down
2 changes: 1 addition & 1 deletion ext/mysqli/tests/mysqli_fetch_object_oo.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ require_once('skipifconnectfailure.inc');
--EXPECTF--
mysqli object is not fully initialized
[0] Object of class mysqli could not be converted to string in %s on line %d
[0] mysqli_result::fetch_object() expects at most 2 parameters, 3 given in %s on line %d
[0] mysqli_result::fetch_object(): At most 2 arguments are expected, 3 given in %s on line %d
[0] mysqli_result::fetch_object(): Argument #2 ($params) must be of type array, null given in %s on line %d
Exception: Too few arguments to function mysqli_fetch_object_construct::__construct(), 1 passed and exactly 2 expected
NULL
Expand Down
4 changes: 2 additions & 2 deletions ext/opcache/tests/optimize_func_calls.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@ Array
(
[0] => A Object
(
[obj] =>
[obj] =>
)

)
Array
(
[0] =>
[0] =>
)
string(7) "changed"
Array
Expand Down
2 changes: 1 addition & 1 deletion ext/phar/tests/002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ try {
}
__HALT_COMPILER(); ?>
--EXPECTF--
Phar::mapPhar() expects at most 2 parameters, 3 given
Phar::mapPhar(): At most 2 arguments are expected, 3 given
internal corruption of phar "%s002.php" (truncated manifest at manifest length)
8 changes: 4 additions & 4 deletions ext/phar/tests/badparameters.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -253,16 +253,16 @@ Phar::compress(): Argument #1 ($compression_type) must be of type int, array giv
Cannot compress phar archive, phar is read-only
Phar::compressFiles(): Argument #1 ($compression_type) must be of type int, array given
Phar is readonly, cannot change compression
Phar::copy() expects exactly 2 parameters, 1 given
Phar::copy(): Exactly 2 arguments are expected, 1 given
Cannot copy "a" to "b", phar is read-only
Phar::offsetExists(): Argument #1 ($entry) must be a valid path, array given
Phar::offsetGet(): Argument #1 ($entry) must be a valid path, array given
Phar::offsetSet() expects exactly 2 parameters, 1 given
Phar::offsetSet(): Exactly 2 arguments are expected, 1 given
PharData::offsetUnset(): Argument #1 ($entry) must be a valid path, array given
Write operations disabled by the php.ini setting phar.readonly
Phar::addEmptyDir(): Argument #1 ($dirname) must be a valid path, array given
Phar::addFile(): Argument #1 ($filename) must be a valid path, array given
Phar::addFromString() expects exactly 2 parameters, 1 given
Phar::addFromString(): Exactly 2 arguments are expected, 1 given
Write operations disabled by the php.ini setting phar.readonly
Phar::setMetadata() expects exactly 1 parameter, 2 given
Phar::setMetadata(): Exactly 1 argument is expected, 2 given
Write operations disabled by the php.ini setting phar.readonly
2 changes: 1 addition & 1 deletion ext/phar/tests/bug60261.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ try {

?>
--EXPECT--
Phar::__construct() expects at least 1 parameter, 0 given
Phar::__construct(): At least 1 argument is expected, 0 given
4 changes: 2 additions & 2 deletions ext/reflection/tests/ReflectionClass_constructor_002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ try {

?>
--EXPECTF--
ReflectionClass::__construct() expects exactly 1 parameter, 0 given
ReflectionClass::__construct(): Exactly 1 argument is expected, 0 given
Class "" does not exist
Class "1" does not exist
Class "1" does not exist

Warning: Array to string conversion in %s on line %d
Class "Array" does not exist
ReflectionClass::__construct() expects exactly 1 parameter, 2 given
ReflectionClass::__construct(): Exactly 1 argument is expected, 2 given
Class "X" does not exist
Loading

0 comments on commit 0257580

Please sign in to comment.