Skip to content

Support Multiple Catch #216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
BPScott opened this issue Feb 13, 2018 · 1 comment
Closed

Support Multiple Catch #216

BPScott opened this issue Feb 13, 2018 · 1 comment

Comments

@BPScott
Copy link

BPScott commented Feb 13, 2018

Support for multiple catch types was added to PHP 7.1 as per https://wiki.php.net/rfc/multiple-catch.
php/php-src#1796 is the PR that merged this feature into php master.

This makes the following code valid in PHP 7.1:

try {
   // Some code...
} catch (ExceptionType1 | ExceptionType2 $e) {
   // Code to handle the exception
}

I'm new to this project (and parsers in general) but from what I can tell the grammar for the try statement should be updated to allow for multiple, pipe-separated qualified-name items.

I think the following grammar is correct:

try-statement:
  'try' compound-statement catch-clauses
  'try' compound-statement finally-clause
  'try' compound-statement catch-clauses finally-clause

catch-clauses:
  catch-clause
  catch-clauses catch-clause

catch-clause:
  'catch' '(' catch-name-list variable-name ')' compound-statement

catch-name-list:
  qualified-name
  catch-name-list '|' qualified-name

finally-clause:
  'finally' compound-statement
@nikic
Copy link
Member

nikic commented Sep 10, 2018

Yup, that grammar looks right. Committed together with some corresponding changes in the text.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants