mirror of
https://github.com/nikic/PHP-Parser.git
synced 2025-07-25 08:11:22 +02:00
Add support for variadic parameters (PHP 5.6)
This commit is contained in:
@@ -13,10 +13,11 @@ array(
|
||||
byRef: false
|
||||
params: array(
|
||||
0: Param(
|
||||
name: a
|
||||
default: null
|
||||
type: null
|
||||
byRef: false
|
||||
variadic: false
|
||||
name: a
|
||||
default: null
|
||||
)
|
||||
)
|
||||
uses: array(
|
||||
@@ -32,10 +33,11 @@ array(
|
||||
byRef: false
|
||||
params: array(
|
||||
0: Param(
|
||||
name: a
|
||||
default: null
|
||||
type: null
|
||||
byRef: false
|
||||
variadic: false
|
||||
name: a
|
||||
default: null
|
||||
)
|
||||
)
|
||||
uses: array(
|
||||
@@ -70,10 +72,11 @@ array(
|
||||
byRef: true
|
||||
params: array(
|
||||
0: Param(
|
||||
name: a
|
||||
default: null
|
||||
type: null
|
||||
byRef: false
|
||||
variadic: false
|
||||
name: a
|
||||
default: null
|
||||
)
|
||||
)
|
||||
uses: array(
|
||||
|
@@ -11,10 +11,11 @@ array(
|
||||
name: a
|
||||
params: array(
|
||||
0: Param(
|
||||
name: b
|
||||
default: null
|
||||
type: null
|
||||
byRef: true
|
||||
variadic: false
|
||||
name: b
|
||||
default: null
|
||||
)
|
||||
)
|
||||
stmts: array(
|
||||
@@ -25,10 +26,11 @@ array(
|
||||
name: a
|
||||
params: array(
|
||||
0: Param(
|
||||
name: b
|
||||
default: null
|
||||
type: null
|
||||
byRef: false
|
||||
variadic: false
|
||||
name: b
|
||||
default: null
|
||||
)
|
||||
)
|
||||
stmts: array(
|
||||
|
@@ -20,6 +20,9 @@ array(
|
||||
name: a
|
||||
params: array(
|
||||
0: Param(
|
||||
type: null
|
||||
byRef: false
|
||||
variadic: false
|
||||
name: b
|
||||
default: Expr_ConstFetch(
|
||||
name: Name(
|
||||
@@ -28,18 +31,20 @@ array(
|
||||
)
|
||||
)
|
||||
)
|
||||
type: null
|
||||
byRef: false
|
||||
)
|
||||
1: Param(
|
||||
type: null
|
||||
byRef: false
|
||||
variadic: false
|
||||
name: c
|
||||
default: Scalar_String(
|
||||
value: foo
|
||||
)
|
||||
type: null
|
||||
byRef: false
|
||||
)
|
||||
2: Param(
|
||||
type: null
|
||||
byRef: false
|
||||
variadic: false
|
||||
name: d
|
||||
default: Expr_ClassConstFetch(
|
||||
class: Name(
|
||||
@@ -49,48 +54,53 @@ array(
|
||||
)
|
||||
name: B
|
||||
)
|
||||
type: null
|
||||
byRef: false
|
||||
)
|
||||
3: Param(
|
||||
type: null
|
||||
byRef: false
|
||||
variadic: false
|
||||
name: f
|
||||
default: Expr_UnaryPlus(
|
||||
expr: Scalar_LNumber(
|
||||
value: 1
|
||||
)
|
||||
)
|
||||
type: null
|
||||
byRef: false
|
||||
)
|
||||
4: Param(
|
||||
type: null
|
||||
byRef: false
|
||||
variadic: false
|
||||
name: g
|
||||
default: Expr_UnaryMinus(
|
||||
expr: Scalar_DNumber(
|
||||
value: 1
|
||||
)
|
||||
)
|
||||
type: null
|
||||
byRef: false
|
||||
)
|
||||
5: Param(
|
||||
type: null
|
||||
byRef: false
|
||||
variadic: false
|
||||
name: h
|
||||
default: Expr_Array(
|
||||
items: array(
|
||||
)
|
||||
)
|
||||
type: null
|
||||
byRef: false
|
||||
)
|
||||
6: Param(
|
||||
type: null
|
||||
byRef: false
|
||||
variadic: false
|
||||
name: i
|
||||
default: Expr_Array(
|
||||
items: array(
|
||||
)
|
||||
)
|
||||
type: null
|
||||
byRef: false
|
||||
)
|
||||
7: Param(
|
||||
type: null
|
||||
byRef: false
|
||||
variadic: false
|
||||
name: j
|
||||
default: Expr_Array(
|
||||
items: array(
|
||||
@@ -103,10 +113,11 @@ array(
|
||||
)
|
||||
)
|
||||
)
|
||||
type: null
|
||||
byRef: false
|
||||
)
|
||||
8: Param(
|
||||
type: null
|
||||
byRef: false
|
||||
variadic: false
|
||||
name: k
|
||||
default: Expr_Array(
|
||||
items: array(
|
||||
@@ -128,8 +139,6 @@ array(
|
||||
)
|
||||
)
|
||||
)
|
||||
type: null
|
||||
byRef: false
|
||||
)
|
||||
)
|
||||
stmts: array(
|
||||
|
@@ -10,32 +10,36 @@ array(
|
||||
name: a
|
||||
params: array(
|
||||
0: Param(
|
||||
name: b
|
||||
default: null
|
||||
type: null
|
||||
byRef: false
|
||||
variadic: false
|
||||
name: b
|
||||
default: null
|
||||
)
|
||||
1: Param(
|
||||
name: c
|
||||
default: null
|
||||
type: array
|
||||
byRef: false
|
||||
variadic: false
|
||||
name: c
|
||||
default: null
|
||||
)
|
||||
2: Param(
|
||||
name: d
|
||||
default: null
|
||||
type: callable
|
||||
byRef: false
|
||||
variadic: false
|
||||
name: d
|
||||
default: null
|
||||
)
|
||||
3: Param(
|
||||
name: f
|
||||
default: null
|
||||
type: Name(
|
||||
parts: array(
|
||||
0: E
|
||||
)
|
||||
)
|
||||
byRef: false
|
||||
variadic: false
|
||||
name: f
|
||||
default: null
|
||||
)
|
||||
)
|
||||
stmts: array(
|
||||
|
106
test/code/parser/stmt/function/variadic.test
Normal file
106
test/code/parser/stmt/function/variadic.test
Normal file
@@ -0,0 +1,106 @@
|
||||
Variadic functions
|
||||
-----
|
||||
<?php
|
||||
function test($a, ... $b) {}
|
||||
function test($a, &... $b) {}
|
||||
function test($a, Type ... $b) {}
|
||||
function test($a, Type &... $b) {}
|
||||
-----
|
||||
array(
|
||||
0: Stmt_Function(
|
||||
byRef: false
|
||||
name: test
|
||||
params: array(
|
||||
0: Param(
|
||||
type: null
|
||||
byRef: false
|
||||
variadic: false
|
||||
name: a
|
||||
default: null
|
||||
)
|
||||
1: Param(
|
||||
type: null
|
||||
byRef: false
|
||||
variadic: true
|
||||
name: b
|
||||
default: null
|
||||
)
|
||||
)
|
||||
stmts: array(
|
||||
)
|
||||
)
|
||||
1: Stmt_Function(
|
||||
byRef: false
|
||||
name: test
|
||||
params: array(
|
||||
0: Param(
|
||||
type: null
|
||||
byRef: false
|
||||
variadic: false
|
||||
name: a
|
||||
default: null
|
||||
)
|
||||
1: Param(
|
||||
type: null
|
||||
byRef: true
|
||||
variadic: true
|
||||
name: b
|
||||
default: null
|
||||
)
|
||||
)
|
||||
stmts: array(
|
||||
)
|
||||
)
|
||||
2: Stmt_Function(
|
||||
byRef: false
|
||||
name: test
|
||||
params: array(
|
||||
0: Param(
|
||||
type: null
|
||||
byRef: false
|
||||
variadic: false
|
||||
name: a
|
||||
default: null
|
||||
)
|
||||
1: Param(
|
||||
type: Name(
|
||||
parts: array(
|
||||
0: Type
|
||||
)
|
||||
)
|
||||
byRef: false
|
||||
variadic: true
|
||||
name: b
|
||||
default: null
|
||||
)
|
||||
)
|
||||
stmts: array(
|
||||
)
|
||||
)
|
||||
3: Stmt_Function(
|
||||
byRef: false
|
||||
name: test
|
||||
params: array(
|
||||
0: Param(
|
||||
type: null
|
||||
byRef: false
|
||||
variadic: false
|
||||
name: a
|
||||
default: null
|
||||
)
|
||||
1: Param(
|
||||
type: Name(
|
||||
parts: array(
|
||||
0: Type
|
||||
)
|
||||
)
|
||||
byRef: true
|
||||
variadic: true
|
||||
name: b
|
||||
default: null
|
||||
)
|
||||
)
|
||||
stmts: array(
|
||||
)
|
||||
)
|
||||
)
|
6
test/code/parser/stmt/function/variadic.test-fail
Normal file
6
test/code/parser/stmt/function/variadic.test-fail
Normal file
@@ -0,0 +1,6 @@
|
||||
Invalid variadic function
|
||||
-----
|
||||
<?php
|
||||
function foo(...$foo = []) {}
|
||||
-----
|
||||
Variadic parameter cannot have a default value on line 2
|
Reference in New Issue
Block a user