Skip to content

Commit 078df4d

Browse files
committed
Don't allow passing unknown named params to class without ctor
See also https://externals.io/message/112083. Closes GH-6364.
1 parent c64dcda commit 078df4d

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
Passing unknown named args to a non-existing ctor
3+
--FILE--
4+
<?php
5+
6+
class Test {}
7+
8+
try {
9+
new stdClass(x: "nope");
10+
} catch (Error $e) {
11+
echo $e->getMessage(), "\n";
12+
}
13+
14+
try {
15+
new Test(x: "nope");
16+
} catch (Error $e) {
17+
echo $e->getMessage(), "\n";
18+
}
19+
20+
?>
21+
--EXPECT--
22+
Unknown named parameter $x
23+
Unknown named parameter $x

Zend/zend_execute.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,12 @@ static ZEND_FUNCTION(pass)
130130
}
131131

132132
ZEND_BEGIN_ARG_INFO_EX(zend_pass_function_arg_info, 0, 0, 0)
133-
ZEND_ARG_VARIADIC_INFO(0, args)
134133
ZEND_END_ARG_INFO()
135134

136135
ZEND_API const zend_internal_function zend_pass_function = {
137136
ZEND_INTERNAL_FUNCTION, /* type */
138137
{0, 0, 0}, /* arg_flags */
139-
ZEND_ACC_VARIADIC, /* fn_flags */
138+
0, /* fn_flags */
140139
NULL, /* name */
141140
NULL, /* scope */
142141
NULL, /* prototype */
@@ -1097,6 +1096,11 @@ static zend_never_inline ZEND_ATTRIBUTE_UNUSED bool zend_verify_internal_arg_typ
10971096
* trust that arginfo matches what is enforced by zend_parse_parameters. */
10981097
static zend_always_inline zend_bool zend_internal_call_should_throw(zend_function *fbc, zend_execute_data *call)
10991098
{
1099+
if (fbc->internal_function.handler == ZEND_FN(pass)) {
1100+
/* Be lenient about the special pass function. */
1101+
return 0;
1102+
}
1103+
11001104
if (fbc->common.required_num_args > ZEND_CALL_NUM_ARGS(call)) {
11011105
/* Required argument not passed. */
11021106
return 1;

0 commit comments

Comments
 (0)