Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Function_.php

class Function_

Same name in this branch
  1. 11.1.x vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/Function_.php \PhpParser\Node\Scalar\MagicConst\Function_
  2. 11.1.x vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Function_.php \PhpParser\Node\Stmt\Function_
  3. 11.1.x vendor/mck89/peast/lib/Peast/Syntax/Node/Function_.php \Peast\Syntax\Node\Function_

Hierarchy

  • class \PhpParser\Builder\Declaration implements \PhpParser\Builder
    • class \PhpParser\Builder\FunctionLike extends \PhpParser\Builder\Declaration
      • class \PhpParser\Builder\Function_ extends \PhpParser\Builder\FunctionLike

Expanded class hierarchy of Function_

File

vendor/nikic/php-parser/lib/PhpParser/Builder/Function_.php, line 10

Namespace

PhpParser\Builder
View source
class Function_ extends FunctionLike {
    protected string $name;
    
    /** @var list<Stmt> */
    protected array $stmts = [];
    
    /** @var list<Node\AttributeGroup> */
    protected array $attributeGroups = [];
    
    /**
     * Creates a function builder.
     *
     * @param string $name Name of the function
     */
    public function __construct(string $name) {
        $this->name = $name;
    }
    
    /**
     * Adds a statement.
     *
     * @param Node|PhpParser\Builder $stmt The statement to add
     *
     * @return $this The builder instance (for fluid interface)
     */
    public function addStmt($stmt) {
        $this->stmts[] = BuilderHelpers::normalizeStmt($stmt);
        return $this;
    }
    
    /**
     * Adds an attribute group.
     *
     * @param Node\Attribute|Node\AttributeGroup $attribute
     *
     * @return $this The builder instance (for fluid interface)
     */
    public function addAttribute($attribute) {
        $this->attributeGroups[] = BuilderHelpers::normalizeAttribute($attribute);
        return $this;
    }
    
    /**
     * Returns the built function node.
     *
     * @return Stmt\Function_ The built function node
     */
    public function getNode() : Node {
        return new Stmt\Function_($this->name, [
            'byRef' => $this->returnByRef,
            'params' => $this->params,
            'returnType' => $this->returnType,
            'stmts' => $this->stmts,
            'attrGroups' => $this->attributeGroups,
        ], $this->attributes);
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
Declaration::$attributes protected property @var array&lt;string, mixed&gt;
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.
Function_::$attributeGroups protected property @var list&lt;Node\AttributeGroup&gt;
Function_::$name protected property
Function_::$stmts protected property @var list&lt;Stmt&gt;
Function_::addAttribute public function Adds an attribute group.
Function_::addStmt public function Adds a statement. Overrides Declaration::addStmt
Function_::getNode public function Returns the built function node. Overrides Builder::getNode
Function_::__construct public function Creates a function builder.

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal