Skip to content

Commit 6111d64

Browse files
committed
Improve a last couple of argument error messages
Closes GH-5404
1 parent 283d37a commit 6111d64

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+105
-107
lines changed

ext/dba/dba.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ static size_t php_dba_make_key(zval *key, char **key_str, char **key_free)
107107
size_t len;
108108

109109
if (zend_hash_num_elements(Z_ARRVAL_P(key)) != 2) {
110-
zend_throw_error(NULL, "Key does not have exactly two elements: (key, name)");
110+
zend_argument_error(NULL, 1, "must have exactly two elements: 'key' and 'name'");
111111
return 0;
112112
}
113113
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(key), &pos);

ext/dba/tests/dba013.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ require(__DIR__ .'/clean.inc');
2424
--EXPECTF--
2525
database handler: %s
2626

27-
Fatal error: Uncaught Error: Key does not have exactly two elements: (key, name) in %sdba013.php:6
27+
Fatal error: Uncaught Error: dba_insert(): Argument #1 ($key) must have exactly two elements: 'key' and 'name' in %s.php:%d
2828
Stack trace:
2929
#0 %sdba013.php(6): dba_insert(Array, '%s', Resource id #%d)
3030
#1 {main}

ext/dba/tests/dba014.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ require(__DIR__ .'/clean.inc');
2424
--EXPECTF--
2525
database handler: %s
2626

27-
Fatal error: Uncaught Error: Key does not have exactly two elements: (key, name) in %sdba014.php:6
27+
Fatal error: Uncaught Error: dba_insert(): Argument #1 ($key) must have exactly two elements: 'key' and 'name' in %s.php:%d
2828
Stack trace:
2929
#0 %sdba014.php(6): dba_insert(Array, '%s', Resource id #%d)
3030
#1 {main}

ext/dom/document.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2082,7 +2082,7 @@ PHP_METHOD(DOMDocument, registerNodeClass)
20822082
RETURN_TRUE;
20832083
}
20842084

2085-
zend_throw_error(NULL, "Class %s is not derived from %s.", ZSTR_VAL(ce->name), ZSTR_VAL(basece->name));
2085+
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));
20862086
}
20872087
/* }}} */
20882088

ext/ffi/ffi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,7 @@ static zval *zend_ffi_cdata_get(zend_object *obj, zend_string *member, int read_
993993
#endif
994994

995995
if (UNEXPECTED(!zend_string_equals_literal(member, "cdata"))) {
996-
zend_throw_error(zend_ffi_exception_ce, "only 'cdata' property may be read");
996+
zend_throw_error(zend_ffi_exception_ce, "Only 'cdata' property may be read");
997997
return &EG(uninitialized_zval);;
998998
}
999999

ext/hash/hash.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -410,9 +410,9 @@ PHP_FUNCTION(hash_init)
410410
}
411411
/* }}} */
412412

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

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

436436
RETURN_TRUE;
@@ -451,7 +451,7 @@ PHP_FUNCTION(hash_update_stream)
451451
}
452452

453453
hash = php_hashcontext_from_object(Z_OBJ_P(zhash));
454-
PHP_HASHCONTEXT_VERIFY("hash_update_stream", hash);
454+
PHP_HASHCONTEXT_VERIFY(hash);
455455
php_stream_from_zval(stream, zstream);
456456

457457
while (length) {
@@ -492,7 +492,7 @@ PHP_FUNCTION(hash_update_file)
492492
}
493493

494494
hash = php_hashcontext_from_object(Z_OBJ_P(zhash));
495-
PHP_HASHCONTEXT_VERIFY("hash_update_file", hash);
495+
PHP_HASHCONTEXT_VERIFY(hash);
496496
context = php_stream_context_from_zval(zcontext, 0);
497497

498498
stream = php_stream_open_wrapper_ex(ZSTR_VAL(filename), "rb", REPORT_ERRORS, NULL, context);
@@ -525,7 +525,7 @@ PHP_FUNCTION(hash_final)
525525
}
526526

527527
hash = php_hashcontext_from_object(Z_OBJ_P(zhash));
528-
PHP_HASHCONTEXT_VERIFY("hash_final", hash);
528+
PHP_HASHCONTEXT_VERIFY(hash);
529529

530530
digest_len = hash->ops->digest_size;
531531
digest = zend_string_alloc(digest_len, 0);

ext/hash/tests/reuse.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ catch (\Error $e) {
1313
}
1414

1515
--EXPECT--
16-
hash_update(): supplied resource is not a valid Hash Context resource
16+
hash_update(): Argument #1 ($context) must be a valid Hash Context resource

ext/mbstring/mbstring.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3333,7 +3333,7 @@ php_mb_numericentity_exec(INTERNAL_FUNCTION_PARAMETERS, int type)
33333333
/* conversion map */
33343334
i = zend_hash_num_elements(target_hash);
33353335
if (i % 4 != 0) {
3336-
zend_value_error("count($convmap) must be a multiple of 4");
3336+
zend_argument_value_error(2, "must have a multiple of 4 elements");
33373337
RETURN_THROWS();
33383338
}
33393339
convmap = (int *)safe_emalloc(i, sizeof(int), 0);

ext/mbstring/tests/mb_decode_numericentity.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,4 @@ aŒbœcŠdše€fg
4242
&#100000000000
4343
&#000000000000
4444
föo
45-
count($convmap) must be a multiple of 4
45+
mb_decode_numericentity(): Argument #2 ($convmap) must have a multiple of 4 elements

ext/mbstring/tests/mb_encode_numericentity.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ try {
3131
ƒΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩαβγδεζηθικλμνξοπρςστυφχψωϑϒϖ•…′″‾⁄℘ℑℜ™ℵ←↑→↓↔↵⇐⇑⇒⇓⇔∀∂∃∅∇∈∉∋∏∑−∗√∝∞∠∧∨∩∪∫∴∼≅≈≠≡≤≥⊂⊃⊄⊆⊇⊕⊗⊥⋅⌈⌉⌊⌋〈〉◊♠♣♥♦
3232
aŒbœcŠdše€fg
3333
föo
34-
count($convmap) must be a multiple of 4
34+
mb_encode_numericentity(): Argument #2 ($convmap) must have a multiple of 4 elements

ext/standard/array.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2396,7 +2396,7 @@ PHP_FUNCTION(extract)
23962396

23972397
if (prefix) {
23982398
if (ZSTR_LEN(prefix) && !php_valid_var_name(ZSTR_VAL(prefix), ZSTR_LEN(prefix))) {
2399-
zend_value_error("Prefix is not a valid identifier");
2399+
zend_argument_value_error(3, "must be a valid identifier");
24002400
RETURN_THROWS();
24012401
}
24022402
}
@@ -2553,7 +2553,7 @@ PHP_FUNCTION(array_fill)
25532553

25542554
if (EXPECTED(num > 0)) {
25552555
if (sizeof(num) > 4 && UNEXPECTED(EXPECTED(num > 0x7fffffff))) {
2556-
zend_value_error("Too many elements");
2556+
zend_argument_value_error(2, "is too large");
25572557
RETURN_THROWS();
25582558
} else if (UNEXPECTED(start_key > ZEND_LONG_MAX - num + 1)) {
25592559
zend_throw_error(NULL, "Cannot add element to the array as the next element is already occupied");
@@ -2602,7 +2602,7 @@ PHP_FUNCTION(array_fill)
26022602
} else if (EXPECTED(num == 0)) {
26032603
RETURN_EMPTY_ARRAY();
26042604
} else {
2605-
zend_value_error("Number of elements can't be negative");
2605+
zend_argument_value_error(2, "must be greater than or equal to 0");
26062606
RETURN_THROWS();
26072607
}
26082608
}
@@ -2843,7 +2843,7 @@ PHP_FUNCTION(range)
28432843
}
28442844
err:
28452845
if (err) {
2846-
zend_value_error("Step exceeds the specified range");
2846+
zend_argument_value_error(3, "must not exceed the specified range");
28472847
RETURN_THROWS();
28482848
}
28492849
}
@@ -4322,7 +4322,7 @@ PHP_FUNCTION(array_pad)
43224322
input_size = zend_hash_num_elements(Z_ARRVAL_P(input));
43234323
pad_size_abs = ZEND_ABS(pad_size);
43244324
if (pad_size_abs < 0 || pad_size_abs - input_size > Z_L(1048576)) {
4325-
zend_value_error("You may only pad up to 1048576 elements at a time");
4325+
zend_argument_value_error(2, "must be less than or equal to 1048576");
43264326
RETURN_THROWS();
43274327
}
43284328

@@ -5790,7 +5790,7 @@ PHP_FUNCTION(array_rand)
57905790
num_avail = zend_hash_num_elements(Z_ARRVAL_P(input));
57915791

57925792
if (num_avail == 0) {
5793-
zend_value_error("Array is empty");
5793+
zend_argument_value_error(1, "cannot be empty");
57945794
RETURN_THROWS();
57955795
}
57965796

@@ -5831,7 +5831,7 @@ PHP_FUNCTION(array_rand)
58315831
}
58325832

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

@@ -6318,7 +6318,7 @@ PHP_FUNCTION(array_chunk)
63186318

63196319
/* Do bounds checking for size parameter. */
63206320
if (size < 1) {
6321-
zend_value_error("Size parameter expected to be greater than 0");
6321+
zend_argument_value_error(2, "must be greater than 0");
63226322
RETURN_THROWS();
63236323
}
63246324

@@ -6387,7 +6387,7 @@ PHP_FUNCTION(array_combine)
63876387
num_values = zend_hash_num_elements(values);
63886388

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

ext/standard/basic_functions.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2477,7 +2477,7 @@ PHP_FUNCTION(register_tick_function)
24772477

24782478
if (!zend_is_callable(&tick_fe.arguments[0], 0, &function_name)) {
24792479
efree(tick_fe.arguments);
2480-
zend_type_error("Invalid tick callback '%s' passed", ZSTR_VAL(function_name));
2480+
zend_argument_type_error(1, "must be a valid tick callback, '%s' given", ZSTR_VAL(function_name));
24812481
zend_string_release_ex(function_name, 0);
24822482
RETURN_THROWS();
24832483
} else if (function_name) {

ext/standard/dir.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ PHP_FUNCTION(readdir)
387387
FETCH_DIRP();
388388

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

ext/standard/file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ PHP_FUNCTION(flock)
348348

349349
act = operation & 3;
350350
if (act < 1 || act > 3) {
351-
zend_value_error("Illegal operation argument");
351+
zend_argument_value_error(2, "must be either LOCK_SH, LOCK_EX, or LOCK_UN");
352352
RETURN_THROWS();
353353
}
354354

ext/standard/math.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,11 +1005,11 @@ PHP_FUNCTION(base_convert)
10051005
}
10061006

10071007
if (frombase < 2 || frombase > 36) {
1008-
zend_value_error("Invalid `from base' (" ZEND_LONG_FMT ")", frombase);
1008+
zend_argument_value_error(2, "must be between 2 and 36 (inclusive)");
10091009
RETURN_THROWS();
10101010
}
10111011
if (tobase < 2 || tobase > 36) {
1012-
zend_value_error("Invalid `to base' (" ZEND_LONG_FMT ")", tobase);
1012+
zend_argument_value_error(3, "must be between 2 and 36 (inclusive)");
10131013
RETURN_THROWS();
10141014
}
10151015

ext/standard/mt_rand.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ PHP_FUNCTION(mt_rand)
325325
ZEND_PARSE_PARAMETERS_END();
326326

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

ext/standard/proc_open.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ PHP_FUNCTION(proc_open)
529529
zval *arg_zv;
530530
uint32_t num_elems = zend_hash_num_elements(Z_ARRVAL_P(command_zv));
531531
if (num_elems == 0) {
532-
zend_value_error("Command array must have at least one element");
532+
zend_argument_value_error(1, "must have at least one element");
533533
RETURN_THROWS();
534534
}
535535

@@ -662,7 +662,7 @@ PHP_FUNCTION(proc_open)
662662
descriptors[ndesc].mode = DESC_FILE;
663663

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

ext/standard/streamsfuncs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1508,7 +1508,7 @@ PHP_FUNCTION(stream_socket_enable_crypto)
15081508
zval *val;
15091509

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

ext/standard/string.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -931,12 +931,12 @@ PHP_FUNCTION(wordwrap)
931931
}
932932

933933
if (breakchar_len == 0) {
934-
zend_value_error("Break string cannot be empty");
934+
zend_argument_value_error(3, "cannot be empty");
935935
RETURN_THROWS();
936936
}
937937

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

@@ -1143,7 +1143,7 @@ PHP_FUNCTION(explode)
11431143
ZEND_PARSE_PARAMETERS_END();
11441144

11451145
if (ZSTR_LEN(delim) == 0) {
1146-
zend_value_error("Empty delimiter");
1146+
zend_argument_value_error(1, "cannot be empty");
11471147
RETURN_THROWS();
11481148
}
11491149

ext/standard/tests/array/array_chunk2.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ var_dump(array_chunk($input_array, 10));
2424
var_dump(array_chunk($input_array, 10, true));
2525
?>
2626
--EXPECT--
27-
Size parameter expected to be greater than 0
28-
Size parameter expected to be greater than 0
27+
array_chunk(): Argument #2 ($size) must be greater than 0
28+
array_chunk(): Argument #2 ($size) must be greater than 0
2929
array(5) {
3030
[0]=>
3131
array(1) {

ext/standard/tests/array/array_chunk_variation5.phpt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ foreach ($sizes as $size){
4949
*** Testing array_chunk() : usage variations ***
5050

5151
-- Testing array_chunk() when size = -1 --
52-
Size parameter expected to be greater than 0
53-
Size parameter expected to be greater than 0
54-
Size parameter expected to be greater than 0
52+
array_chunk(): Argument #2 ($size) must be greater than 0
53+
array_chunk(): Argument #2 ($size) must be greater than 0
54+
array_chunk(): Argument #2 ($size) must be greater than 0
5555

5656
-- Testing array_chunk() when size = 4 --
5757
array(1) {
@@ -89,9 +89,9 @@ array(1) {
8989
}
9090

9191
-- Testing array_chunk() when size = 0 --
92-
Size parameter expected to be greater than 0
93-
Size parameter expected to be greater than 0
94-
Size parameter expected to be greater than 0
92+
array_chunk(): Argument #2 ($size) must be greater than 0
93+
array_chunk(): Argument #2 ($size) must be greater than 0
94+
array_chunk(): Argument #2 ($size) must be greater than 0
9595

9696
-- Testing array_chunk() when size = 1.5 --
9797
array(3) {

ext/standard/tests/array/array_combine_error2.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ array(0) {
4747
}
4848

4949
-- Testing array_combine() function with empty array for $keys argument --
50-
Both parameters should have an equal number of elements
50+
array_combine(): Argument #1 ($keys) and argument #2 ($values) must have the same number of elements
5151
-- Testing array_combine() function with empty array for $values argument --
52-
Both parameters should have an equal number of elements
52+
array_combine(): Argument #1 ($keys) and argument #2 ($values) must have the same number of elements
5353
-- Testing array_combine() function by passing array with unequal number of elements --
54-
Both parameters should have an equal number of elements
54+
array_combine(): Argument #1 ($keys) and argument #2 ($values) must have the same number of elements

ext/standard/tests/array/array_fill_error.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ try {
2424
?>
2525
--EXPECT--
2626
*** Testing array_fill() : error conditions ***
27-
Number of elements can't be negative
27+
array_fill(): Argument #2 ($num) must be greater than or equal to 0

ext/standard/tests/array/array_pad.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,4 @@ array(4) {
8484
[3]=>
8585
float(2)
8686
}
87-
You may only pad up to 1048576 elements at a time
87+
array_pad(): Argument #2 ($pad_size) must be less than or equal to 1048576

ext/standard/tests/array/array_rand.phpt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ var_dump(array_rand(array(1,2,3), 2));
3838

3939
?>
4040
--EXPECTF--
41-
Array is empty
42-
Array is empty
43-
Second argument has to be between 1 and the number of elements in the array
44-
Second argument has to be between 1 and the number of elements in the array
45-
Second argument has to be between 1 and the number of elements in the array
41+
array_rand(): Argument #1 ($arg) cannot be empty
42+
array_rand(): Argument #1 ($arg) cannot be empty
43+
array_rand(): Argument #2 ($num_req) must be between 1 and the number of elements in argument #1 ($arg)
44+
array_rand(): Argument #2 ($num_req) must be between 1 and the number of elements in argument #1 ($arg)
45+
array_rand(): Argument #2 ($num_req) must be between 1 and the number of elements in argument #1 ($arg)
4646
array(3) {
4747
[0]=>
4848
int(%d)

ext/standard/tests/array/array_rand_variation5.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@ int(%d)
7070
int(%d)
7171

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

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

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

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

0 commit comments

Comments
 (0)