1 <?php declare(strict_types=1);
3 namespace PhpParser\Node\Stmt;
6 use PhpParser\Node\FunctionLike;
9 * @property Node\Name $namespacedName Namespaced name (if using NameResolver)
11 class Function_ extends Node\Stmt implements FunctionLike
13 /** @var bool Whether function returns by reference */
15 /** @var Node\Identifier Name */
17 /** @var Node\Param[] Parameters */
19 /** @var null|Node\Identifier|Node\Name|Node\NullableType Return type */
21 /** @var Node\Stmt[] Statements */
25 * Constructs a function node.
27 * @param string|Node\Identifier $name Name
28 * @param array $subNodes Array of the following optional subnodes:
29 * 'byRef' => false : Whether to return by reference
30 * 'params' => array(): Parameters
31 * 'returnType' => null : Return type
32 * 'stmts' => array(): Statements
33 * @param array $attributes Additional attributes
35 public function __construct($name, array $subNodes = [], array $attributes = []) {
36 parent::__construct($attributes);
37 $this->byRef = $subNodes['byRef'] ?? false;
38 $this->name = \is_string($name) ? new Node\Identifier($name) : $name;
39 $this->params = $subNodes['params'] ?? [];
40 $returnType = $subNodes['returnType'] ?? null;
41 $this->returnType = \is_string($returnType) ? new Node\Identifier($returnType) : $returnType;
42 $this->stmts = $subNodes['stmts'] ?? [];
45 public function getSubNodeNames() : array {
46 return ['byRef', 'name', 'params', 'returnType', 'stmts'];
49 public function returnsByRef() : bool {
53 public function getParams() : array {
57 public function getReturnType() {
58 return $this->returnType;
61 /** @return Node\Stmt[] */
62 public function getStmts() : array {
66 public function getType() : string {
67 return 'Stmt_Function';