Skip to content

Improve a last couple of argument error messages #5404

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 4 commits 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
2 changes: 1 addition & 1 deletion ext/dba/dba.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ static size_t php_dba_make_key(zval *key, char **key_str, char **key_free)
size_t len;

if (zend_hash_num_elements(Z_ARRVAL_P(key)) != 2) {
zend_throw_error(NULL, "Key does not have exactly two elements: (key, name)");
zend_argument_error(NULL, 1, "must have exactly two elements: 'key' and 'name'");
return 0;
}
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(key), &pos);
Expand Down
2 changes: 1 addition & 1 deletion ext/dba/tests/dba013.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ require(__DIR__ .'/clean.inc');
--EXPECTF--
database handler: %s

Fatal error: Uncaught Error: Key does not have exactly two elements: (key, name) in %sdba013.php:6
Fatal error: Uncaught Error: dba_insert(): Argument #1 ($key) must have exactly two elements: 'key' and 'name' in %s.php:%d
Stack trace:
#0 %sdba013.php(6): dba_insert(Array, '%s', Resource id #%d)
#1 {main}
Expand Down
2 changes: 1 addition & 1 deletion ext/dba/tests/dba014.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ require(__DIR__ .'/clean.inc');
--EXPECTF--
database handler: %s

Fatal error: Uncaught Error: Key does not have exactly two elements: (key, name) in %sdba014.php:6
Fatal error: Uncaught Error: dba_insert(): Argument #1 ($key) must have exactly two elements: 'key' and 'name' in %s.php:%d
Stack trace:
#0 %sdba014.php(6): dba_insert(Array, '%s', Resource id #%d)
#1 {main}
Expand Down
2 changes: 1 addition & 1 deletion ext/dom/document.c
Original file line number Diff line number Diff line change
Expand Up @@ -2082,7 +2082,7 @@ PHP_METHOD(DOMDocument, registerNodeClass)
RETURN_TRUE;
}

zend_throw_error(NULL, "Class %s is not derived from %s.", ZSTR_VAL(ce->name), ZSTR_VAL(basece->name));
zend_argument_error(NULL, 2, "must be a class name derived from %s or null, '%s' given", ZSTR_VAL(basece->name), ZSTR_VAL(ce->name));
}
/* }}} */

Expand Down
2 changes: 1 addition & 1 deletion ext/ffi/ffi.c
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,7 @@ static zval *zend_ffi_cdata_get(zend_object *obj, zend_string *member, int read_
#endif

if (UNEXPECTED(!zend_string_equals_literal(member, "cdata"))) {
zend_throw_error(zend_ffi_exception_ce, "only 'cdata' property may be read");
zend_throw_error(zend_ffi_exception_ce, "Only 'cdata' property may be read");
return &EG(uninitialized_zval);;
}

Expand Down
12 changes: 6 additions & 6 deletions ext/hash/hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,9 @@ PHP_FUNCTION(hash_init)
}
/* }}} */

#define PHP_HASHCONTEXT_VERIFY(func, hash) { \
#define PHP_HASHCONTEXT_VERIFY(hash) { \
if (!hash->context) { \
zend_throw_error(NULL, "%s(): supplied resource is not a valid Hash Context resource", func); \
zend_argument_type_error(1, "must be a valid Hash Context resource"); \
RETURN_THROWS(); \
} \
}
Expand All @@ -430,7 +430,7 @@ PHP_FUNCTION(hash_update)
}

hash = php_hashcontext_from_object(Z_OBJ_P(zhash));
PHP_HASHCONTEXT_VERIFY("hash_update", hash);
PHP_HASHCONTEXT_VERIFY(hash);
hash->ops->hash_update(hash->context, (unsigned char *) ZSTR_VAL(data), ZSTR_LEN(data));

RETURN_TRUE;
Expand All @@ -451,7 +451,7 @@ PHP_FUNCTION(hash_update_stream)
}

hash = php_hashcontext_from_object(Z_OBJ_P(zhash));
PHP_HASHCONTEXT_VERIFY("hash_update_stream", hash);
PHP_HASHCONTEXT_VERIFY(hash);
php_stream_from_zval(stream, zstream);

while (length) {
Expand Down Expand Up @@ -492,7 +492,7 @@ PHP_FUNCTION(hash_update_file)
}

hash = php_hashcontext_from_object(Z_OBJ_P(zhash));
PHP_HASHCONTEXT_VERIFY("hash_update_file", hash);
PHP_HASHCONTEXT_VERIFY(hash);
context = php_stream_context_from_zval(zcontext, 0);

stream = php_stream_open_wrapper_ex(ZSTR_VAL(filename), "rb", REPORT_ERRORS, NULL, context);
Expand Down Expand Up @@ -525,7 +525,7 @@ PHP_FUNCTION(hash_final)
}

hash = php_hashcontext_from_object(Z_OBJ_P(zhash));
PHP_HASHCONTEXT_VERIFY("hash_final", hash);
PHP_HASHCONTEXT_VERIFY(hash);

digest_len = hash->ops->digest_size;
digest = zend_string_alloc(digest_len, 0);
Expand Down
2 changes: 1 addition & 1 deletion ext/hash/tests/reuse.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ catch (\Error $e) {
}

--EXPECT--
hash_update(): supplied resource is not a valid Hash Context resource
hash_update(): Argument #1 ($context) must be a valid Hash Context resource
2 changes: 1 addition & 1 deletion ext/mbstring/mbstring.c
Original file line number Diff line number Diff line change
Expand Up @@ -3333,7 +3333,7 @@ php_mb_numericentity_exec(INTERNAL_FUNCTION_PARAMETERS, int type)
/* conversion map */
i = zend_hash_num_elements(target_hash);
if (i % 4 != 0) {
zend_value_error("count($convmap) must be a multiple of 4");
zend_argument_value_error(2, "must have a multiple of 4 elements");
RETURN_THROWS();
}
convmap = (int *)safe_emalloc(i, sizeof(int), 0);
Expand Down
2 changes: 1 addition & 1 deletion ext/mbstring/tests/mb_decode_numericentity.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ aŒbœcŠdše€fg
&#100000000000
&#000000000000
föo
count($convmap) must be a multiple of 4
mb_decode_numericentity(): Argument #2 ($convmap) must have a multiple of 4 elements
2 changes: 1 addition & 1 deletion ext/mbstring/tests/mb_encode_numericentity.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ try {
ƒΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩαβγδεζηθικλμνξοπρςστυφχψωϑϒϖ•…′″‾⁄℘ℑℜ™ℵ←↑→↓↔↵⇐⇑⇒⇓⇔∀∂∃∅∇∈∉∋∏∑−∗√∝∞∠∧∨∩∪∫∴∼≅≈≠≡≤≥⊂⊃⊄⊆⊇⊕⊗⊥⋅⌈⌉⌊⌋〈〉◊♠♣♥♦
aŒbœcŠdše€fg
föo
count($convmap) must be a multiple of 4
mb_encode_numericentity(): Argument #2 ($convmap) must have a multiple of 4 elements
18 changes: 9 additions & 9 deletions ext/standard/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -2396,7 +2396,7 @@ PHP_FUNCTION(extract)

if (prefix) {
if (ZSTR_LEN(prefix) && !php_valid_var_name(ZSTR_VAL(prefix), ZSTR_LEN(prefix))) {
zend_value_error("Prefix is not a valid identifier");
zend_argument_value_error(3, "must be a valid identifier");
RETURN_THROWS();
}
}
Expand Down Expand Up @@ -2553,7 +2553,7 @@ PHP_FUNCTION(array_fill)

if (EXPECTED(num > 0)) {
if (sizeof(num) > 4 && UNEXPECTED(EXPECTED(num > 0x7fffffff))) {
zend_value_error("Too many elements");
zend_argument_value_error(2, "is too large");
RETURN_THROWS();
} else if (UNEXPECTED(start_key > ZEND_LONG_MAX - num + 1)) {
zend_throw_error(NULL, "Cannot add element to the array as the next element is already occupied");
Expand Down Expand Up @@ -2602,7 +2602,7 @@ PHP_FUNCTION(array_fill)
} else if (EXPECTED(num == 0)) {
RETURN_EMPTY_ARRAY();
} else {
zend_value_error("Number of elements can't be negative");
zend_argument_value_error(2, "must be greater than or equal to 0");
RETURN_THROWS();
}
}
Expand Down Expand Up @@ -2843,7 +2843,7 @@ PHP_FUNCTION(range)
}
err:
if (err) {
zend_value_error("Step exceeds the specified range");
zend_argument_value_error(3, "must not exceed the specified range");
RETURN_THROWS();
}
}
Expand Down Expand Up @@ -4322,7 +4322,7 @@ PHP_FUNCTION(array_pad)
input_size = zend_hash_num_elements(Z_ARRVAL_P(input));
pad_size_abs = ZEND_ABS(pad_size);
if (pad_size_abs < 0 || pad_size_abs - input_size > Z_L(1048576)) {
zend_value_error("You may only pad up to 1048576 elements at a time");
zend_argument_value_error(2, "must be less than or equal to 1048576");
RETURN_THROWS();
}

Expand Down Expand Up @@ -5790,7 +5790,7 @@ PHP_FUNCTION(array_rand)
num_avail = zend_hash_num_elements(Z_ARRVAL_P(input));

if (num_avail == 0) {
zend_value_error("Array is empty");
zend_argument_value_error(1, "cannot be empty");
RETURN_THROWS();
}

Expand Down Expand Up @@ -5831,7 +5831,7 @@ PHP_FUNCTION(array_rand)
}

if (num_req <= 0 || num_req > num_avail) {
zend_value_error("Second argument has to be between 1 and the number of elements in the array");
zend_argument_value_error(2, "must be between 1 and the number of elements in argument #1 ($arg)");
RETURN_THROWS();
}

Expand Down Expand Up @@ -6318,7 +6318,7 @@ PHP_FUNCTION(array_chunk)

/* Do bounds checking for size parameter. */
if (size < 1) {
zend_value_error("Size parameter expected to be greater than 0");
zend_argument_value_error(2, "must be greater than 0");
RETURN_THROWS();
}

Expand Down Expand Up @@ -6387,7 +6387,7 @@ PHP_FUNCTION(array_combine)
num_values = zend_hash_num_elements(values);

if (num_keys != num_values) {
zend_value_error("Both parameters should have an equal number of elements");
zend_argument_value_error(1, "and argument #2 ($values) must have the same number of elements");
RETURN_THROWS();
}

Expand Down
2 changes: 1 addition & 1 deletion ext/standard/basic_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -2477,7 +2477,7 @@ PHP_FUNCTION(register_tick_function)

if (!zend_is_callable(&tick_fe.arguments[0], 0, &function_name)) {
efree(tick_fe.arguments);
zend_type_error("Invalid tick callback '%s' passed", ZSTR_VAL(function_name));
zend_argument_type_error(1, "must be a valid tick callback, '%s' given", ZSTR_VAL(function_name));
zend_string_release_ex(function_name, 0);
RETURN_THROWS();
} else if (function_name) {
Expand Down
2 changes: 1 addition & 1 deletion ext/standard/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ PHP_FUNCTION(readdir)
FETCH_DIRP();

if (!(dirp->flags & PHP_STREAM_FLAG_IS_DIR)) {
zend_type_error("%d is not a valid Directory resource", dirp->res->handle);
zend_argument_type_error(1, "must be a valid Directory resource");
RETURN_THROWS();
}

Expand Down
2 changes: 1 addition & 1 deletion ext/standard/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ PHP_FUNCTION(flock)

act = operation & 3;
if (act < 1 || act > 3) {
zend_value_error("Illegal operation argument");
zend_argument_value_error(2, "must be either LOCK_SH, LOCK_EX, or LOCK_UN");
RETURN_THROWS();
}

Expand Down
4 changes: 2 additions & 2 deletions ext/standard/math.c
Original file line number Diff line number Diff line change
Expand Up @@ -1005,11 +1005,11 @@ PHP_FUNCTION(base_convert)
}

if (frombase < 2 || frombase > 36) {
zend_value_error("Invalid `from base' (" ZEND_LONG_FMT ")", frombase);
zend_argument_value_error(2, "must be between 2 and 36 (inclusive)");
RETURN_THROWS();
}
if (tobase < 2 || tobase > 36) {
zend_value_error("Invalid `to base' (" ZEND_LONG_FMT ")", tobase);
zend_argument_value_error(3, "must be between 2 and 36 (inclusive)");
RETURN_THROWS();
}

Expand Down
2 changes: 1 addition & 1 deletion ext/standard/mt_rand.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ PHP_FUNCTION(mt_rand)
ZEND_PARSE_PARAMETERS_END();

if (UNEXPECTED(max < min)) {
zend_value_error("max (" ZEND_LONG_FMT ") is smaller than min (" ZEND_LONG_FMT ")", max, min);
zend_argument_value_error(2, "must be greater than or equal to argument #1 ($min)");
RETURN_THROWS();
}

Expand Down
4 changes: 2 additions & 2 deletions ext/standard/proc_open.c
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ PHP_FUNCTION(proc_open)
zval *arg_zv;
uint32_t num_elems = zend_hash_num_elements(Z_ARRVAL_P(command_zv));
if (num_elems == 0) {
zend_value_error("Command array must have at least one element");
zend_argument_value_error(1, "must have at least one element");
RETURN_THROWS();
}

Expand Down Expand Up @@ -662,7 +662,7 @@ PHP_FUNCTION(proc_open)
descriptors[ndesc].mode = DESC_FILE;

} else if (Z_TYPE_P(descitem) != IS_ARRAY) {
zend_value_error("Descriptor item must be either an array or a File-Handle");
zend_argument_value_error(2, "must only contain arrays and File-Handles");
goto exit_fail;
} else {

Expand Down
2 changes: 1 addition & 1 deletion ext/standard/streamsfuncs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1508,7 +1508,7 @@ PHP_FUNCTION(stream_socket_enable_crypto)
zval *val;

if (!GET_CTX_OPT(stream, "ssl", "crypto_method", val)) {
zend_value_error("When enabling encryption you must specify the crypto type");
zend_argument_value_error(3, "must be specified when enabling encryption");
RETURN_THROWS();
}

Expand Down
6 changes: 3 additions & 3 deletions ext/standard/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -931,12 +931,12 @@ PHP_FUNCTION(wordwrap)
}

if (breakchar_len == 0) {
zend_value_error("Break string cannot be empty");
zend_argument_value_error(3, "cannot be empty");
RETURN_THROWS();
}

if (linelength == 0 && docut) {
zend_value_error("Can't force cut when width is zero");
zend_argument_value_error(4, "cannot be true when argument #2 ($width) is 0");
RETURN_THROWS();
}

Expand Down Expand Up @@ -1143,7 +1143,7 @@ PHP_FUNCTION(explode)
ZEND_PARSE_PARAMETERS_END();

if (ZSTR_LEN(delim) == 0) {
zend_value_error("Empty delimiter");
zend_argument_value_error(1, "cannot be empty");
RETURN_THROWS();
}

Expand Down
4 changes: 2 additions & 2 deletions ext/standard/tests/array/array_chunk2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ var_dump(array_chunk($input_array, 10));
var_dump(array_chunk($input_array, 10, true));
?>
--EXPECT--
Size parameter expected to be greater than 0
Size parameter expected to be greater than 0
array_chunk(): Argument #2 ($size) must be greater than 0
array_chunk(): Argument #2 ($size) must be greater than 0
array(5) {
[0]=>
array(1) {
Expand Down
12 changes: 6 additions & 6 deletions ext/standard/tests/array/array_chunk_variation5.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ foreach ($sizes as $size){
*** Testing array_chunk() : usage variations ***

-- Testing array_chunk() when size = -1 --
Size parameter expected to be greater than 0
Size parameter expected to be greater than 0
Size parameter expected to be greater than 0
array_chunk(): Argument #2 ($size) must be greater than 0
array_chunk(): Argument #2 ($size) must be greater than 0
array_chunk(): Argument #2 ($size) must be greater than 0

-- Testing array_chunk() when size = 4 --
array(1) {
Expand Down Expand Up @@ -89,9 +89,9 @@ array(1) {
}

-- Testing array_chunk() when size = 0 --
Size parameter expected to be greater than 0
Size parameter expected to be greater than 0
Size parameter expected to be greater than 0
array_chunk(): Argument #2 ($size) must be greater than 0
array_chunk(): Argument #2 ($size) must be greater than 0
array_chunk(): Argument #2 ($size) must be greater than 0

-- Testing array_chunk() when size = 1.5 --
array(3) {
Expand Down
6 changes: 3 additions & 3 deletions ext/standard/tests/array/array_combine_error2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ array(0) {
}

-- Testing array_combine() function with empty array for $keys argument --
Both parameters should have an equal number of elements
array_combine(): Argument #1 ($keys) and argument #2 ($values) must have the same number of elements
-- Testing array_combine() function with empty array for $values argument --
Both parameters should have an equal number of elements
array_combine(): Argument #1 ($keys) and argument #2 ($values) must have the same number of elements
-- Testing array_combine() function by passing array with unequal number of elements --
Both parameters should have an equal number of elements
array_combine(): Argument #1 ($keys) and argument #2 ($values) must have the same number of elements
2 changes: 1 addition & 1 deletion ext/standard/tests/array/array_fill_error.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ try {
?>
--EXPECT--
*** Testing array_fill() : error conditions ***
Number of elements can't be negative
array_fill(): Argument #2 ($num) must be greater than or equal to 0
2 changes: 1 addition & 1 deletion ext/standard/tests/array/array_pad.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,4 @@ array(4) {
[3]=>
float(2)
}
You may only pad up to 1048576 elements at a time
array_pad(): Argument #2 ($pad_size) must be less than or equal to 1048576
10 changes: 5 additions & 5 deletions ext/standard/tests/array/array_rand.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ var_dump(array_rand(array(1,2,3), 2));

?>
--EXPECTF--
Array is empty
Array is empty
Second argument has to be between 1 and the number of elements in the array
Second argument has to be between 1 and the number of elements in the array
Second argument has to be between 1 and the number of elements in the array
array_rand(): Argument #1 ($arg) cannot be empty
array_rand(): Argument #1 ($arg) cannot be empty
array_rand(): Argument #2 ($num_req) must be between 1 and the number of elements in argument #1 ($arg)
array_rand(): Argument #2 ($num_req) must be between 1 and the number of elements in argument #1 ($arg)
array_rand(): Argument #2 ($num_req) must be between 1 and the number of elements in argument #1 ($arg)
array(3) {
[0]=>
int(%d)
Expand Down
8 changes: 4 additions & 4 deletions ext/standard/tests/array/array_rand_variation5.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ int(%d)
int(%d)

-- With num_req = 0 --
Second argument has to be between 1 and the number of elements in the array
array_rand(): Argument #2 ($num_req) must be between 1 and the number of elements in argument #1 ($arg)

-- With num_req = -1 --
Second argument has to be between 1 and the number of elements in the array
array_rand(): Argument #2 ($num_req) must be between 1 and the number of elements in argument #1 ($arg)

-- With num_req = -2 --
Second argument has to be between 1 and the number of elements in the array
array_rand(): Argument #2 ($num_req) must be between 1 and the number of elements in argument #1 ($arg)

-- With num_req more than number of members in 'input' array --
Second argument has to be between 1 and the number of elements in the array
array_rand(): Argument #2 ($num_req) must be between 1 and the number of elements in argument #1 ($arg)
Loading