Skip to content

Commit b5f5313

Browse files
TomasVotrubanikic
authored andcommitted
[PHP 8.0] Add exception witout variable
1 parent 32f8966 commit b5f5313

File tree

6 files changed

+293
-231
lines changed

6 files changed

+293
-231
lines changed

grammar/php7.y

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ name_union:
269269
;
270270

271271
catch:
272-
T_CATCH '(' name_union plain_variable ')' '{' inner_statement_list '}'
272+
T_CATCH '(' name_union optional_plain_variable ')' '{' inner_statement_list '}'
273273
{ $$ = Stmt\Catch_[$3, $4, $7]; }
274274
;
275275

@@ -916,6 +916,11 @@ callable_variable:
916916
{ $$ = Expr\MethodCall[$1, $3, $4]; }
917917
;
918918

919+
optional_plain_variable:
920+
/* empty */ { $$ = null; }
921+
| plain_variable { $$ = $1; }
922+
;
923+
919924
variable:
920925
callable_variable { $$ = $1; }
921926
| static_member { $$ = $1; }

lib/PhpParser/Node/Stmt/Catch_.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,21 @@ class Catch_ extends Node\Stmt
99
{
1010
/** @var Node\Name[] Types of exceptions to catch */
1111
public $types;
12-
/** @var Expr\Variable Variable for exception */
12+
/** @var Expr\Variable|null Variable for exception */
1313
public $var;
1414
/** @var Node\Stmt[] Statements */
1515
public $stmts;
1616

1717
/**
1818
* Constructs a catch node.
1919
*
20-
* @param Node\Name[] $types Types of exceptions to catch
21-
* @param Expr\Variable $var Variable for exception
22-
* @param Node\Stmt[] $stmts Statements
23-
* @param array $attributes Additional attributes
20+
* @param Node\Name[] $types Types of exceptions to catch
21+
* @param Expr\Variable|null $var Variable for exception
22+
* @param Node\Stmt[] $stmts Statements
23+
* @param array $attributes Additional attributes
2424
*/
2525
public function __construct(
26-
array $types, Expr\Variable $var, array $stmts = [], array $attributes = []
26+
array $types, Expr\Variable $var = null, array $stmts = [], array $attributes = []
2727
) {
2828
$this->attributes = $attributes;
2929
$this->types = $types;
@@ -34,7 +34,7 @@ public function __construct(
3434
public function getSubNodeNames() : array {
3535
return ['types', 'var', 'stmts'];
3636
}
37-
37+
3838
public function getType() : string {
3939
return 'Stmt_Catch';
4040
}

0 commit comments

Comments
 (0)