Skip to content

Commit 817e7a3

Browse files
committed
Adjust error messages
1 parent 574c566 commit 817e7a3

File tree

4 files changed

+35
-31
lines changed

4 files changed

+35
-31
lines changed

Zend/tests/partial_application/errors_001.phpt

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,45 @@ function foo($a, $b, $c) {
66

77
}
88

9+
class C {
10+
function f($a, $b, $c) {
11+
}
12+
}
13+
914
try {
1015
foo(?);
1116
} catch (Error $ex) {
12-
printf("%s\n", $ex->getMessage());
17+
printf("%s: %s\n", $ex::class, $ex->getMessage());
1318
}
1419

1520
try {
1621
foo(?, ?, ?, ?);
1722
} catch (Error $ex) {
18-
printf("%s\n", $ex->getMessage());
23+
printf("%s: %s\n", $ex::class, $ex->getMessage());
24+
}
25+
26+
try {
27+
$c = new C();
28+
$c->f(?);
29+
} catch (Error $ex) {
30+
printf("%s: %s\n", $ex::class, $ex->getMessage());
1931
}
2032

2133
try {
2234
property_exists(?);
2335
} catch (Error $ex) {
24-
printf("%s\n", $ex->getMessage());
36+
printf("%s: %s\n", $ex::class, $ex->getMessage());
2537
}
2638

2739
try {
2840
usleep(?, ?);
2941
} catch (Error $ex) {
30-
printf("%s\n", $ex->getMessage());
42+
printf("%s: %s\n", $ex::class, $ex->getMessage());
3143
}
3244
?>
3345
--EXPECT--
34-
not enough arguments or placeholders for application of foo, 1 given and exactly 3 expected
35-
too many arguments or placeholders for application of foo, 4 given and a maximum of 3 expected
36-
not enough arguments or placeholders for application of property_exists, 1 given and exactly 2 expected
37-
too many arguments or placeholders for application of usleep, 2 given and a maximum of 1 expected
46+
ArgumentCountError: Partial application of foo() expects exactly 3 arguments, 1 given
47+
ArgumentCountError: Partial application of foo() expects at most 3 arguments, 4 given
48+
ArgumentCountError: Partial application of C::f() expects exactly 3 arguments, 1 given
49+
ArgumentCountError: Partial application of property_exists() expects exactly 2 arguments, 1 given
50+
ArgumentCountError: Partial application of usleep() expects at most 1 arguments, 2 given

Zend/tests/partial_application/rfc_examples_003.phpt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,23 @@ if (time() > 0) {
1010
try {
1111
stuff(?);
1212
} catch (Error $e) {
13-
echo $e->getMessage(), "\n";
13+
echo $e::class, ": ", $e->getMessage(), "\n";
1414
}
1515

1616
try {
1717
stuff(?, ?, ?, ?, ?, ?);
1818
} catch (Error $e) {
19-
echo $e->getMessage(), "\n";
19+
echo $e::class, ": ", $e->getMessage(), "\n";
2020
}
2121

2222
try {
2323
stuff(?, ?, 3.5, null, i: 5);
2424
} catch (Error $e) {
25-
echo $e->getMessage(), "\n";
25+
echo $e::class, ": ", $e->getMessage(), "\n";
2626
}
2727

2828
?>
29-
--EXPECTF--
30-
not enough arguments or placeholders for application of stuff, 1 given and at least 4 expected
31-
too many arguments or placeholders for application of stuff, 6 given and a maximum of 5 expected
32-
Named parameter $i overwrites previous placeholder
29+
--EXPECT--
30+
ArgumentCountError: Partial application of stuff() expects at least 4 arguments, 1 given
31+
ArgumentCountError: Partial application of stuff() expects at most 5 arguments, 6 given
32+
Error: Named parameter $i overwrites previous placeholder

Zend/tests/partial_application/variation_variadics_008.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ try {
1313
}
1414
?>
1515
--EXPECTF--
16-
too many arguments or placeholders for application of {closure:%s}, 2 given and a maximum of 1 expected
16+
Partial application of {closure:%s:%d}() expects at most 1 arguments, 2 given

Zend/zend_partial.c

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,27 +57,18 @@ static zend_always_inline void zend_partial_args_underflow(
5757
const char *limit = function->common.num_args <= function->common.required_num_args ?
5858
"exactly" : "at least";
5959

60-
zend_throw_error(NULL,
61-
"not enough arguments or placeholders for application of %s, "
62-
"%d given and %s %d expected",
63-
ZSTR_VAL(symbol), args, limit, expected);
60+
zend_argument_count_error(
61+
"Partial application of %s() expects %s %d arguments, %d given",
62+
ZSTR_VAL(symbol), limit, expected, args);
6463
}
6564

6665
static zend_always_inline void zend_partial_args_overflow(
6766
zend_function *function, zend_string *symbol, uint32_t args,
6867
uint32_t expected)
6968
{
70-
if (function->type == ZEND_USER_FUNCTION) {
71-
zend_throw_error(NULL,
72-
"too many arguments or placeholders for application of %s, "
73-
"%d given and a maximum of %d expected",
74-
ZSTR_VAL(symbol), args, expected);
75-
} else {
76-
zend_throw_error(NULL,
77-
"too many arguments or placeholders for application of %s, "
78-
"%d given and a maximum of %d expected",
79-
ZSTR_VAL(symbol), args, expected);
80-
}
69+
zend_argument_count_error(
70+
"Partial application of %s() expects at most %d arguments, %d given",
71+
ZSTR_VAL(symbol), expected, args);
8172
}
8273

8374
void zend_partial_args_check(zend_execute_data *call) {

0 commit comments

Comments
 (0)