TryCatch.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace PhpParser\Node\Stmt;
  3. use PhpParser\Node;
  4. use PhpParser\Error;
  5. class TryCatch extends Node\Stmt
  6. {
  7. /** @var Node[] Statements */
  8. public $stmts;
  9. /** @var Catch_[] Catches */
  10. public $catches;
  11. /** @var null|Node[] Finally statements */
  12. public $finallyStmts;
  13. /**
  14. * Constructs a try catch node.
  15. *
  16. * @param Node[] $stmts Statements
  17. * @param Catch_[] $catches Catches
  18. * @param null|Node[] $finallyStmts Finally statements (null means no finally clause)
  19. * @param array|null $attributes Additional attributes
  20. */
  21. public function __construct(array $stmts, array $catches, array $finallyStmts = null, array $attributes = array()) {
  22. if (empty($catches) && null === $finallyStmts) {
  23. throw new Error('Cannot use try without catch or finally');
  24. }
  25. parent::__construct(null, $attributes);
  26. $this->stmts = $stmts;
  27. $this->catches = $catches;
  28. $this->finallyStmts = $finallyStmts;
  29. }
  30. public function getSubNodeNames() {
  31. return array('stmts', 'catches', 'finallyStmts');
  32. }
  33. }