3 namespace PhpParser\Builder;
8 abstract class FunctionLike extends Declaration
10 protected $returnByRef = false;
11 protected $params = array();
13 /** @var string|Node\Name|Node\NullableType|null */
14 protected $returnType = null;
17 * Make the function return by reference.
19 * @return $this The builder instance (for fluid interface)
21 public function makeReturnByRef() {
22 $this->returnByRef = true;
30 * @param Node\Param|Param $param The parameter to add
32 * @return $this The builder instance (for fluid interface)
34 public function addParam($param) {
35 $param = $this->normalizeNode($param);
37 if (!$param instanceof Node\Param) {
38 throw new \LogicException(sprintf('Expected parameter node, got "%s"', $param->getType()));
41 $this->params[] = $param;
47 * Adds multiple parameters.
49 * @param array $params The parameters to add
51 * @return $this The builder instance (for fluid interface)
53 public function addParams(array $params) {
54 foreach ($params as $param) {
55 $this->addParam($param);
62 * Sets the return type for PHP 7.
64 * @param string|Node\Name|Node\NullableType $type One of array, callable, string, int, float, bool, iterable,
65 * or a class/interface name.
67 * @return $this The builder instance (for fluid interface)
69 public function setReturnType($type)
71 $this->returnType = $this->normalizeType($type);