diff --git a/grammar/php.y b/grammar/php.y index b962a5e079..e825d038e3 100644 --- a/grammar/php.y +++ b/grammar/php.y @@ -840,7 +840,7 @@ class_statement: #if PHP8 | optional_attributes variable_modifiers optional_type_without_static property_declaration_list '{' property_hook_list '}' { $$ = new Stmt\Property($2, $4, attributes(), $3, $1, $6); - $this->checkPropertyHookList($6, #5); } + $this->checkEmptyPropertyHookList($6, #5); } #endif | optional_attributes method_modifiers T_CONST class_const_list semi { $$ = new Stmt\ClassConst($4, $2, attributes(), $1); @@ -949,7 +949,7 @@ property_hook_list: optional_property_hook_list: /* empty */ { $$ = []; } #if PHP8 - | '{' property_hook_list '}' { $$ = $2; $this->checkPropertyHookList($2, #1); } + | '{' property_hook_list '}' { $$ = $2; $this->checkEmptyPropertyHookList($2, #1); } #endif ; diff --git a/lib/PhpParser/Parser/Php8.php b/lib/PhpParser/Parser/Php8.php index e1aa4b1f3e..f9cb6338fa 100644 --- a/lib/PhpParser/Parser/Php8.php +++ b/lib/PhpParser/Parser/Php8.php @@ -1993,7 +1993,7 @@ protected function initReduceCallbacks(): void { }, 348 => static function ($self, $stackPos) { $self->semValue = new Stmt\Property($self->semStack[$stackPos-(7-2)], $self->semStack[$stackPos-(7-4)], $self->getAttributes($self->tokenStartStack[$stackPos-(7-1)], $self->tokenEndStack[$stackPos]), $self->semStack[$stackPos-(7-3)], $self->semStack[$stackPos-(7-1)], $self->semStack[$stackPos-(7-6)]); - $self->checkPropertyHookList($self->semStack[$stackPos-(7-6)], $stackPos-(7-5)); + $self->checkEmptyPropertyHookList($self->semStack[$stackPos-(7-6)], $stackPos-(7-5)); }, 349 => static function ($self, $stackPos) { $self->semValue = new Stmt\ClassConst($self->semStack[$stackPos-(5-4)], $self->semStack[$stackPos-(5-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(5-1)], $self->tokenEndStack[$stackPos]), $self->semStack[$stackPos-(5-1)]); @@ -2122,7 +2122,7 @@ protected function initReduceCallbacks(): void { $self->semValue = []; }, 394 => static function ($self, $stackPos) { - $self->semValue = $self->semStack[$stackPos-(3-2)]; $self->checkPropertyHookList($self->semStack[$stackPos-(3-2)], $stackPos-(3-1)); + $self->semValue = $self->semStack[$stackPos-(3-2)]; $self->checkEmptyPropertyHookList($self->semStack[$stackPos-(3-2)], $stackPos-(3-1)); }, 395 => static function ($self, $stackPos) { $self->semValue = new Node\PropertyHook($self->semStack[$stackPos-(5-4)], $self->semStack[$stackPos-(5-5)], ['flags' => $self->semStack[$stackPos-(5-2)], 'byRef' => $self->semStack[$stackPos-(5-3)], 'params' => [], 'attrGroups' => $self->semStack[$stackPos-(5-1)]], $self->getAttributes($self->tokenStartStack[$stackPos-(5-1)], $self->tokenEndStack[$stackPos])); diff --git a/lib/PhpParser/ParserAbstract.php b/lib/PhpParser/ParserAbstract.php index 45902037ba..6921a66fe9 100644 --- a/lib/PhpParser/ParserAbstract.php +++ b/lib/PhpParser/ParserAbstract.php @@ -1159,7 +1159,7 @@ protected function checkUseUse(UseItem $node, int $namePos): void { } /** @param PropertyHook[] $hooks */ - protected function checkPropertyHookList(array $hooks, int $hookPos): void { + protected function checkEmptyPropertyHookList(array $hooks, int $hookPos): void { if (empty($hooks)) { $this->emitError(new Error( 'Property hook list cannot be empty', $this->getAttributesAt($hookPos)));