diff --git a/grammar/php.y b/grammar/php.y index 719eb941..05ebd13e 100644 --- a/grammar/php.y +++ b/grammar/php.y @@ -386,16 +386,7 @@ non_empty_statement: $$ = Stmt\InlineHTML[$1]; $$->setAttribute('hasLeadingNewline', $this->inlineHtmlHasLeadingNewline(#1)); } - | expr semi { - $e = $1; - if ($e instanceof Expr\Throw_) { - // For backwards-compatibility reasons, convert throw in statement position into - // Stmt\Throw_ rather than Stmt\Expression(Expr\Throw_). - $$ = Stmt\Throw_[$e->expr]; - } else { - $$ = Stmt\Expression[$e]; - } - } + | expr semi { $$ = Stmt\Expression[$1]; } | T_UNSET '(' variables_list ')' semi { $$ = Stmt\Unset_[$3]; } | T_FOREACH '(' expr T_AS foreach_variable ')' foreach_statement { $$ = Stmt\Foreach_[$3, $5[0], ['keyVar' => null, 'byRef' => $5[1], 'stmts' => $7]]; } diff --git a/lib/PhpParser/Node/Stmt/Throw_.php b/lib/PhpParser/Node/Stmt/Throw_.php deleted file mode 100644 index 52a7ae40..00000000 --- a/lib/PhpParser/Node/Stmt/Throw_.php +++ /dev/null @@ -1,29 +0,0 @@ - $attributes Additional attributes - */ - public function __construct(Node\Expr $expr, array $attributes = []) { - $this->attributes = $attributes; - $this->expr = $expr; - } - - public function getSubNodeNames(): array { - return ['expr']; - } - - public function getType(): string { - return 'Stmt_Throw'; - } -} diff --git a/lib/PhpParser/Parser/Php7.php b/lib/PhpParser/Parser/Php7.php index b20b7412..e1729027 100644 --- a/lib/PhpParser/Parser/Php7.php +++ b/lib/PhpParser/Parser/Php7.php @@ -1473,16 +1473,7 @@ class Php7 extends \PhpParser\ParserAbstract }, 172 => function ($stackPos) { - - $e = $this->semStack[$stackPos-(2-1)]; - if ($e instanceof Expr\Throw_) { - // For backwards-compatibility reasons, convert throw in statement position into - // Stmt\Throw_ rather than Stmt\Expression(Expr\Throw_). - $this->semValue = new Stmt\Throw_($e->expr, $this->getAttributes($this->tokenStartStack[$stackPos-(2-1)], $this->tokenEndStack[$stackPos])); - } else { - $this->semValue = new Stmt\Expression($e, $this->getAttributes($this->tokenStartStack[$stackPos-(2-1)], $this->tokenEndStack[$stackPos])); - } - + $this->semValue = new Stmt\Expression($this->semStack[$stackPos-(2-1)], $this->getAttributes($this->tokenStartStack[$stackPos-(2-1)], $this->tokenEndStack[$stackPos])); }, 173 => function ($stackPos) { $this->semValue = new Stmt\Unset_($this->semStack[$stackPos-(5-3)], $this->getAttributes($this->tokenStartStack[$stackPos-(5-1)], $this->tokenEndStack[$stackPos])); diff --git a/lib/PhpParser/Parser/Php8.php b/lib/PhpParser/Parser/Php8.php index fcc3f0f1..718af9cd 100644 --- a/lib/PhpParser/Parser/Php8.php +++ b/lib/PhpParser/Parser/Php8.php @@ -1491,16 +1491,7 @@ class Php8 extends \PhpParser\ParserAbstract }, 172 => function ($stackPos) { - - $e = $this->semStack[$stackPos-(2-1)]; - if ($e instanceof Expr\Throw_) { - // For backwards-compatibility reasons, convert throw in statement position into - // Stmt\Throw_ rather than Stmt\Expression(Expr\Throw_). - $this->semValue = new Stmt\Throw_($e->expr, $this->getAttributes($this->tokenStartStack[$stackPos-(2-1)], $this->tokenEndStack[$stackPos])); - } else { - $this->semValue = new Stmt\Expression($e, $this->getAttributes($this->tokenStartStack[$stackPos-(2-1)], $this->tokenEndStack[$stackPos])); - } - + $this->semValue = new Stmt\Expression($this->semStack[$stackPos-(2-1)], $this->getAttributes($this->tokenStartStack[$stackPos-(2-1)], $this->tokenEndStack[$stackPos])); }, 173 => function ($stackPos) { $this->semValue = new Stmt\Unset_($this->semStack[$stackPos-(5-3)], $this->getAttributes($this->tokenStartStack[$stackPos-(5-1)], $this->tokenEndStack[$stackPos])); diff --git a/lib/PhpParser/PrettyPrinter/Standard.php b/lib/PhpParser/PrettyPrinter/Standard.php index 69cb4c2a..6a0349c7 100644 --- a/lib/PhpParser/PrettyPrinter/Standard.php +++ b/lib/PhpParser/PrettyPrinter/Standard.php @@ -960,10 +960,6 @@ class Standard extends PrettyPrinterAbstract { return 'return' . (null !== $node->expr ? ' ' . $this->p($node->expr) : '') . ';'; } - protected function pStmt_Throw(Stmt\Throw_ $node): string { - return 'throw ' . $this->p($node->expr) . ';'; - } - protected function pStmt_Label(Stmt\Label $node): string { return $node->name . ':'; } diff --git a/test/code/parser/errorHandling/recovery.test b/test/code/parser/errorHandling/recovery.test index 7fab35ba..1293ba55 100644 --- a/test/code/parser/errorHandling/recovery.test +++ b/test/code/parser/errorHandling/recovery.test @@ -525,9 +525,11 @@ array( ) ) ) - 12: Stmt_Throw( - expr: Expr_Variable( - name: x + 12: Stmt_Expression( + expr: Expr_Throw( + expr: Expr_Variable( + name: x + ) ) ) 13: Stmt_Goto( diff --git a/test/code/parser/stmt/controlFlow.test b/test/code/parser/stmt/controlFlow.test index be786f9a..bad95a54 100644 --- a/test/code/parser/stmt/controlFlow.test +++ b/test/code/parser/stmt/controlFlow.test @@ -41,9 +41,11 @@ array( name: a ) ) - 6: Stmt_Throw( - expr: Expr_Variable( - name: e + 6: Stmt_Expression( + expr: Expr_Throw( + expr: Expr_Variable( + name: e + ) ) ) 7: Stmt_Label(