Skip to content

Commit

Permalink
[PHP 8.0] Add exception witout variable
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba authored and nikic committed Jun 3, 2020
1 parent 32f8966 commit b5f5313
Show file tree
Hide file tree
Showing 6 changed files with 293 additions and 231 deletions.
7 changes: 6 additions & 1 deletion grammar/php7.y
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ name_union:
;

catch:
T_CATCH '(' name_union plain_variable ')' '{' inner_statement_list '}'
T_CATCH '(' name_union optional_plain_variable ')' '{' inner_statement_list '}'
{ $$ = Stmt\Catch_[$3, $4, $7]; }
;

Expand Down Expand Up @@ -916,6 +916,11 @@ callable_variable:
{ $$ = Expr\MethodCall[$1, $3, $4]; }
;

optional_plain_variable:
/* empty */ { $$ = null; }
| plain_variable { $$ = $1; }
;

variable:
callable_variable { $$ = $1; }
| static_member { $$ = $1; }
Expand Down
14 changes: 7 additions & 7 deletions lib/PhpParser/Node/Stmt/Catch_.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ class Catch_ extends Node\Stmt
{
/** @var Node\Name[] Types of exceptions to catch */
public $types;
/** @var Expr\Variable Variable for exception */
/** @var Expr\Variable|null Variable for exception */
public $var;
/** @var Node\Stmt[] Statements */
public $stmts;

/**
* Constructs a catch node.
*
* @param Node\Name[] $types Types of exceptions to catch
* @param Expr\Variable $var Variable for exception
* @param Node\Stmt[] $stmts Statements
* @param array $attributes Additional attributes
* @param Node\Name[] $types Types of exceptions to catch
* @param Expr\Variable|null $var Variable for exception
* @param Node\Stmt[] $stmts Statements
* @param array $attributes Additional attributes
*/
public function __construct(
array $types, Expr\Variable $var, array $stmts = [], array $attributes = []
array $types, Expr\Variable $var = null, array $stmts = [], array $attributes = []
) {
$this->attributes = $attributes;
$this->types = $types;
Expand All @@ -34,7 +34,7 @@ public function __construct(
public function getSubNodeNames() : array {
return ['types', 'var', 'stmts'];
}

public function getType() : string {
return 'Stmt_Catch';
}
Expand Down
Loading

0 comments on commit b5f5313

Please sign in to comment.