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

0 commit comments

Comments
 (0)