1 <?php declare(strict_types=1);
3 namespace PhpParser\Node\Expr;
6 use PhpParser\Node\Expr;
7 use PhpParser\Node\FunctionLike;
9 class Closure extends Expr implements FunctionLike
11 /** @var bool Whether the closure is static */
13 /** @var bool Whether to return by reference */
15 /** @var Node\Param[] Parameters */
17 /** @var ClosureUse[] use()s */
19 /** @var null|Node\Identifier|Node\Name|Node\NullableType Return type */
21 /** @var Node\Stmt[] Statements */
25 * Constructs a lambda function node.
27 * @param array $subNodes Array of the following optional subnodes:
28 * 'static' => false : Whether the closure is static
29 * 'byRef' => false : Whether to return by reference
30 * 'params' => array(): Parameters
31 * 'uses' => array(): use()s
32 * 'returnType' => null : Return type
33 * 'stmts' => array(): Statements
34 * @param array $attributes Additional attributes
36 public function __construct(array $subNodes = [], array $attributes = []) {
37 parent::__construct($attributes);
38 $this->static = $subNodes['static'] ?? false;
39 $this->byRef = $subNodes['byRef'] ?? false;
40 $this->params = $subNodes['params'] ?? [];
41 $this->uses = $subNodes['uses'] ?? [];
42 $returnType = $subNodes['returnType'] ?? null;
43 $this->returnType = \is_string($returnType) ? new Node\Identifier($returnType) : $returnType;
44 $this->stmts = $subNodes['stmts'] ?? [];
47 public function getSubNodeNames() : array {
48 return ['static', 'byRef', 'params', 'uses', 'returnType', 'stmts'];
51 public function returnsByRef() : bool {
55 public function getParams() : array {
59 public function getReturnType() {
60 return $this->returnType;
63 /** @return Node\Stmt[] */
64 public function getStmts() : array {
68 public function getType() : string {
69 return 'Expr_Closure';