Skip to content

Commit b9111b7

Browse files
committed
Fix arg count check when a variadic placeholder exists
1 parent f220277 commit b9111b7

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

Zend/tests/partial_application/errors_001.phpt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,18 @@ try {
4141
} catch (Error $ex) {
4242
printf("%s: %s\n", $ex::class, $ex->getMessage());
4343
}
44+
45+
try {
46+
foo(?, ?, ?, ?, ...);
47+
} catch (Error $ex) {
48+
printf("%s: %s\n", $ex::class, $ex->getMessage());
49+
}
50+
4451
?>
4552
--EXPECT--
4653
ArgumentCountError: Partial application of foo() expects exactly 3 arguments, 1 given
4754
ArgumentCountError: Partial application of foo() expects at most 3 arguments, 4 given
4855
ArgumentCountError: Partial application of C::f() expects exactly 3 arguments, 1 given
4956
ArgumentCountError: Partial application of property_exists() expects exactly 2 arguments, 1 given
5057
ArgumentCountError: Partial application of usleep() expects at most 1 arguments, 2 given
58+
ArgumentCountError: Partial application of foo() expects at most 3 arguments, 4 given

Zend/zend_partial.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,20 +94,18 @@ static zend_result zp_args_check(const zend_function *function,
9494
} ZEND_HASH_FOREACH_END();
9595
}
9696

97-
// TODO: should be just 'argc', since the placeholder param doesn't increase argc?
98-
uint32_t num = argc + (uses_variadic_placeholder ? -1 : 0);
99-
100-
if (num < function->common.required_num_args) {
97+
if (argc < function->common.required_num_args) {
10198
if (uses_variadic_placeholder) {
99+
/* Missing args will be turned into placeholders */
102100
return SUCCESS;
103101
}
104102

105103
zend_partial_args_underflow(
106-
function, num, function->common.required_num_args);
104+
function, argc, function->common.required_num_args);
107105
return FAILURE;
108-
} else if (num > function->common.num_args &&
106+
} else if (argc > function->common.num_args &&
109107
!(function->common.fn_flags & ZEND_ACC_VARIADIC)) {
110-
zend_partial_args_overflow(function, num, function->common.num_args);
108+
zend_partial_args_overflow(function, argc, function->common.num_args);
111109
return FAILURE;
112110
}
113111

0 commit comments

Comments
 (0)