class FunctionLike
Hierarchy
- class \PhpParser\Builder\Declaration implements \PhpParser\Builder
- class \PhpParser\Builder\FunctionLike extends \PhpParser\Builder\Declaration
Expanded class hierarchy of FunctionLike
File
-
vendor/
nikic/ php-parser/ lib/ PhpParser/ Builder/ FunctionLike.php, line 8
Namespace
PhpParser\BuilderView source
abstract class FunctionLike extends Declaration {
protected bool $returnByRef = false;
/** @var Node\Param[] */
protected array $params = [];
/** @var Node\Identifier|Node\Name|Node\ComplexType|null */
protected ?Node $returnType = null;
/**
* Make the function return by reference.
*
* @return $this The builder instance (for fluid interface)
*/
public function makeReturnByRef() {
$this->returnByRef = true;
return $this;
}
/**
* Adds a parameter.
*
* @param Node\Param|Param $param The parameter to add
*
* @return $this The builder instance (for fluid interface)
*/
public function addParam($param) {
$param = BuilderHelpers::normalizeNode($param);
if (!$param instanceof Node\Param) {
throw new \LogicException(sprintf('Expected parameter node, got "%s"', $param->getType()));
}
$this->params[] = $param;
return $this;
}
/**
* Adds multiple parameters.
*
* @param (Node\Param|Param)[] $params The parameters to add
*
* @return $this The builder instance (for fluid interface)
*/
public function addParams(array $params) {
foreach ($params as $param) {
$this->addParam($param);
}
return $this;
}
/**
* Sets the return type for PHP 7.
*
* @param string|Node\Name|Node\Identifier|Node\ComplexType $type
*
* @return $this The builder instance (for fluid interface)
*/
public function setReturnType($type) {
$this->returnType = BuilderHelpers::normalizeType($type);
return $this;
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overrides |
---|---|---|---|---|
Builder::getNode | public | function | Returns the built node. | 14 |
Declaration::$attributes | protected | property | @var array<string, mixed> | |
Declaration::addStmt | abstract public | function | Adds a statement. | 7 |
Declaration::addStmts | public | function | Adds multiple statements. | |
Declaration::setDocComment | public | function | Sets doc comment for the declaration. | |
FunctionLike::$params | protected | property | @var Node\Param[] | |
FunctionLike::$returnByRef | protected | property | ||
FunctionLike::$returnType | protected | property | @var Node\Identifier|Node\Name|Node\ComplexType|null | |
FunctionLike::addParam | public | function | Adds a parameter. | |
FunctionLike::addParams | public | function | Adds multiple parameters. | |
FunctionLike::makeReturnByRef | public | function | Make the function return by reference. | |
FunctionLike::setReturnType | public | function | Sets the return type for PHP 7. |