Param.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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|UnionType 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. /** @var int */
  17. public $flags;
  18. /** @var AttributeGroup[] PHP attribute groups */
  19. public $attrGroups;
  20. /**
  21. * Constructs a parameter node.
  22. *
  23. * @param Expr\Variable|Expr\Error $var Parameter variable
  24. * @param null|Expr $default Default value
  25. * @param null|string|Identifier|Name|NullableType|UnionType $type Type declaration
  26. * @param bool $byRef Whether is passed by reference
  27. * @param bool $variadic Whether this is a variadic argument
  28. * @param array $attributes Additional attributes
  29. * @param int $flags Optional visibility flags
  30. * @param AttributeGroup[] $attrGroups PHP attribute groups
  31. */
  32. public function __construct(
  33. $var, Expr $default = null, $type = null,
  34. bool $byRef = false, bool $variadic = false,
  35. array $attributes = [],
  36. int $flags = 0,
  37. array $attrGroups = []
  38. ) {
  39. $this->attributes = $attributes;
  40. $this->type = \is_string($type) ? new Identifier($type) : $type;
  41. $this->byRef = $byRef;
  42. $this->variadic = $variadic;
  43. $this->var = $var;
  44. $this->default = $default;
  45. $this->flags = $flags;
  46. $this->attrGroups = $attrGroups;
  47. }
  48. public function getSubNodeNames() : array {
  49. return ['attrGroups', 'flags', 'type', 'byRef', 'variadic', 'var', 'default'];
  50. }
  51. public function getType() : string {
  52. return 'Param';
  53. }
  54. }