Param.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace PhpParser\Node;
  3. use PhpParser\Error;
  4. use PhpParser\NodeAbstract;
  5. class Param extends NodeAbstract
  6. {
  7. /** @var null|string|Name Typehint */
  8. public $type;
  9. /** @var bool Whether parameter is passed by reference */
  10. public $byRef;
  11. /** @var bool Whether this is a variadic argument */
  12. public $variadic;
  13. /** @var string Name */
  14. public $name;
  15. /** @var null|Expr Default value */
  16. public $default;
  17. /**
  18. * Constructs a parameter node.
  19. *
  20. * @param string $name Name
  21. * @param null|Expr $default Default value
  22. * @param null|string|Name $type Typehint
  23. * @param bool $byRef Whether is passed by reference
  24. * @param bool $variadic Whether this is a variadic argument
  25. * @param array $attributes Additional attributes
  26. */
  27. public function __construct($name, Expr $default = null, $type = null, $byRef = false, $variadic = false, array $attributes = array()) {
  28. parent::__construct($attributes);
  29. $this->type = $type;
  30. $this->byRef = $byRef;
  31. $this->variadic = $variadic;
  32. $this->name = $name;
  33. $this->default = $default;
  34. if ($variadic && null !== $default) {
  35. throw new Error('Variadic parameter cannot have a default value', $default->getAttributes());
  36. }
  37. }
  38. public function getSubNodeNames() {
  39. return array('type', 'byRef', 'variadic', 'name', 'default');
  40. }
  41. }