Param.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php declare(strict_types=1);
  2. namespace PhpParser\Node;
  3. use PhpParser\NodeAbstract;
  4. class Param extends NodeAbstract
  5. {
  6. /** @var null|Identifier|Name|NullableType Type declaration */
  7. public $type;
  8. /** @var bool Whether parameter is passed by reference */
  9. public $byRef;
  10. /** @var bool Whether this is a variadic argument */
  11. public $variadic;
  12. /** @var Expr\Variable|Expr\Error Parameter variable */
  13. public $var;
  14. /** @var null|Expr Default value */
  15. public $default;
  16. /**
  17. * Constructs a parameter node.
  18. *
  19. * @param Expr\Variable|Expr\Error $var Parameter variable
  20. * @param null|Expr $default Default value
  21. * @param null|string|Identifier|Name|NullableType $type Type declaration
  22. * @param bool $byRef Whether is passed by reference
  23. * @param bool $variadic Whether this is a variadic argument
  24. * @param array $attributes Additional attributes
  25. */
  26. public function __construct(
  27. $var, Expr $default = null, $type = null,
  28. bool $byRef = false, bool $variadic = false, array $attributes = []
  29. ) {
  30. parent::__construct($attributes);
  31. $this->type = \is_string($type) ? new Identifier($type) : $type;
  32. $this->byRef = $byRef;
  33. $this->variadic = $variadic;
  34. $this->var = $var;
  35. $this->default = $default;
  36. }
  37. public function getSubNodeNames() : array {
  38. return ['type', 'byRef', 'variadic', 'var', 'default'];
  39. }
  40. public function getType() : string {
  41. return 'Param';
  42. }
  43. }