Skip to content

Commit 8511641

Browse files
committed
feat: allow no statements inside the constructor
1 parent d154c72 commit 8511641

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
--TEST--
2+
Class does not contain any statements
3+
--FILE--
4+
<?php
5+
6+
class DTO;
7+
8+
?>
9+
--EXPECTF--

Zend/zend_language_parser.y

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ static YYSIZE_T zend_yytnamerr(char*, const char*);
252252
%token T_ERROR
253253

254254
%type <ast> top_statement namespace_name name statement function_declaration_statement
255-
%type <ast> class_declaration_statement trait_declaration_statement legacy_namespace_name
255+
%type <ast> class_declaration_statement class_body_statement trait_declaration_statement legacy_namespace_name
256256
%type <ast> interface_declaration_statement interface_extends_list
257257
%type <ast> group_use_declaration inline_use_declarations inline_use_declaration
258258
%type <ast> mixed_group_use_declaration use_declaration unprefixed_use_declaration
@@ -291,7 +291,7 @@ static YYSIZE_T zend_yytnamerr(char*, const char*);
291291

292292
%type <num> returns_ref function fn is_reference is_variadic property_modifiers property_hook_modifiers
293293
%type <num> method_modifiers class_const_modifiers member_modifier optional_cpp_modifiers
294-
%type <num> class_modifiers class_modifier anonymous_class_modifiers anonymous_class_modifiers_optional use_type backup_fn_flags
294+
%type <num> class_modifiers class_modifiers_optional class_modifier anonymous_class_modifiers anonymous_class_modifiers_optional use_type backup_fn_flags
295295

296296
%type <ptr> backup_lex_pos
297297
%type <str> backup_doc_comment
@@ -602,12 +602,18 @@ is_variadic:
602602
;
603603

604604
class_declaration_statement:
605-
class_modifiers T_CLASS { $<num>$ = CG(zend_lineno); }
606-
T_STRING extends_from implements_list backup_doc_comment '{' class_statement_list '}'
607-
{ $$ = zend_ast_create_decl(ZEND_AST_CLASS, $1, $<num>3, $7, zend_ast_get_str($4), $5, $6, $9, NULL, NULL); }
608-
| T_CLASS { $<num>$ = CG(zend_lineno); }
609-
T_STRING extends_from implements_list backup_doc_comment '{' class_statement_list '}'
610-
{ $$ = zend_ast_create_decl(ZEND_AST_CLASS, 0, $<num>2, $6, zend_ast_get_str($3), $4, $5, $8, NULL, NULL); }
605+
class_modifiers_optional T_CLASS { $<num>$ = CG(zend_lineno); } T_STRING
606+
extends_from implements_list backup_doc_comment class_body_statement
607+
{ $$ = zend_ast_create_decl(ZEND_AST_CLASS, $1, $<num>3, $7, zend_ast_get_str($4), $5, $6, $8, NULL, NULL); }
608+
;
609+
610+
class_body_statement:
611+
'{' class_statement_list '}' { $$ = $2; }
612+
| ';' { $$ = NULL; }
613+
614+
class_modifiers_optional:
615+
%empty { $$ = 0; }
616+
| class_modifiers { $$ = $1; }
611617
;
612618

613619
class_modifiers:

0 commit comments

Comments
 (0)