Skip to content

Commit faaf65b

Browse files
committed
Prevent void param type
1 parent 8c360e2 commit faaf65b

File tree

3 files changed

+81
-0
lines changed

3 files changed

+81
-0
lines changed

lib/PhpParser/ParserAbstract.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,6 +1078,13 @@ protected function checkParam(Param $node): void {
10781078
$node->default->getAttributes()
10791079
));
10801080
}
1081+
1082+
if ($node->type instanceof Identifier && $node->type->name === 'void') {
1083+
$this->emitError(new Error(
1084+
'Parameter type cannot be void',
1085+
$node->type->getAttributes()
1086+
));
1087+
}
10811088
}
10821089

10831090
protected function checkTryCatch(TryCatch $node): void {
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
Invalid parameter with type void
2+
-----
3+
<?php
4+
function foo(void $foo) {}
5+
-----
6+
Parameter type cannot be void from 2:14 to 2:17
7+
array(
8+
0: Stmt_Function(
9+
attrGroups: array(
10+
)
11+
byRef: false
12+
name: Identifier(
13+
name: foo
14+
)
15+
params: array(
16+
0: Param(
17+
attrGroups: array(
18+
)
19+
flags: 0
20+
type: Identifier(
21+
name: void
22+
)
23+
byRef: false
24+
variadic: false
25+
var: Expr_Variable(
26+
name: foo
27+
)
28+
default: null
29+
hooks: array(
30+
)
31+
)
32+
)
33+
returnType: null
34+
stmts: array(
35+
)
36+
)
37+
)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
Valid parameter with type void
2+
-----
3+
<?php
4+
function foo(void $foo) {}
5+
-----
6+
!!version=7.0
7+
array(
8+
0: Stmt_Function(
9+
attrGroups: array(
10+
)
11+
byRef: false
12+
name: Identifier(
13+
name: foo
14+
)
15+
params: array(
16+
0: Param(
17+
attrGroups: array(
18+
)
19+
flags: 0
20+
type: Name(
21+
name: void
22+
)
23+
byRef: false
24+
variadic: false
25+
var: Expr_Variable(
26+
name: foo
27+
)
28+
default: null
29+
hooks: array(
30+
)
31+
)
32+
)
33+
returnType: null
34+
stmts: array(
35+
)
36+
)
37+
)

0 commit comments

Comments
 (0)