From 0aed2cc2a440e7be17552cc669d71fdd24d1204a Mon Sep 17 00:00:00 2001 From: Pierrick Charron Date: Sun, 1 May 2016 18:47:08 -0400 Subject: Allow catching multiple exception types in a single catch statement This commit add the possibility to catch multiple exception types in a single catch statement to avoid code duplication. try { // Some code... } catch (ExceptionType1 | ExceptionType2 $e) { // Code to handle the exception } catch (\Exception $e) { // ... } --- Zend/zend_language_parser.y | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'Zend/zend_language_parser.y') diff --git a/Zend/zend_language_parser.y b/Zend/zend_language_parser.y index 53b2f3f50b..4722846ce7 100644 --- a/Zend/zend_language_parser.y +++ b/Zend/zend_language_parser.y @@ -245,7 +245,7 @@ static YYSIZE_T zend_yytnamerr(char*, const char*); %type encaps_var encaps_var_offset isset_variables %type top_statement_list use_declarations const_list inner_statement_list if_stmt %type alt_if_stmt for_exprs switch_case_list global_var_list static_var_list -%type echo_expr_list unset_variables catch_list parameter_list class_statement_list +%type echo_expr_list unset_variables catch_name_list catch_list parameter_list class_statement_list %type implements_list case_list if_stmt_without_else %type non_empty_parameter_list argument_list non_empty_argument_list property_list %type class_const_list class_const_decl name_list trait_adaptations method_body non_empty_for_exprs @@ -456,10 +456,15 @@ statement: catch_list: /* empty */ { $$ = zend_ast_create_list(0, ZEND_AST_CATCH_LIST); } - | catch_list T_CATCH '(' name T_VARIABLE ')' '{' inner_statement_list '}' + | catch_list T_CATCH '(' catch_name_list T_VARIABLE ')' '{' inner_statement_list '}' { $$ = zend_ast_list_add($1, zend_ast_create(ZEND_AST_CATCH, $4, $5, $8)); } ; +catch_name_list: + name { $$ = zend_ast_create_list(1, ZEND_AST_NAME_LIST, $1); } + | catch_name_list '|' name { $$ = zend_ast_list_add($1, $3); } +; + finally_statement: /* empty */ { $$ = NULL; } | T_FINALLY '{' inner_statement_list '}' { $$ = $3; } -- cgit v1.2.1