Skip to content
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

fix: interface properties #395

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

nataneb32
Copy link

@nataneb32 nataneb32 commented Dec 21, 2022

typed interfaces property declaration as broken

$missingInterfaceMemberDeclaration->parent = $parentNode;
$missingInterfaceMemberDeclaration->modifiers = $modifiers;
return $missingInterfaceMemberDeclaration;
return $this->parseRemainingPropertyDeclarationOrMissingMemberDeclaration($parentNode, $modifiers);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

possible to add a test for this? or what is a code example that would invoke this change?

@TysonAndre
Copy link
Contributor

This change has a point, though it seems unrelated to the root cause of the bug in the linked ticket. PHP internally parses class_statement_list the same way for classes, enums, traits, interfaces. So property declarations in interfaces would be a compile-time error, not a parser error, and tolerant-php-parser is meant to be a tolerant parser (and applications using this should be checking for compilation errors)

https://github.com/php/php-src/blob/PHP-8.3.1/Zend/zend_language_parser.y#L622-L638

@TysonAndre
Copy link
Contributor

TysonAndre commented Dec 26, 2023

I guess .php stubs for UnitEnum/BackedEnum interfaces in php would have fake $name/$value(BackedEnum) properties for documentation in IDEs/editors?

This is still a compile-time error in php 8.3 (not a parser error). My personal preference is to unify the parsing of all the class-likes into one helper method but I hadn't found it that urgent

php > interface foo { public int $x; }

Fatal error: Interfaces may not include properties in php shell code on line 1
php > class Foo { case X = 123; }

Fatal error: Case can only be used in enums in php shell code on line 1

TysonAndre added a commit to TysonAndre/tolerant-php-parser that referenced this pull request Dec 26, 2023
Using a class-like member in the wrong class-like is a compile-time
error, not a parsing error. Tolerate it and parse the current/remaining
statements and leave it to the applications to warn about using
unexpected members in classes, traits, interfaces, or enums.
(Or to tolerate them for stubs for editors/IDEs)

Related to microsoft#395
TysonAndre added a commit to TysonAndre/tolerant-php-parser that referenced this pull request Dec 26, 2023
Using a class-like member in the wrong class-like is a compile-time
error, not a parsing error. Tolerate it and parse the current/remaining
statements and leave it to the applications to warn about using
unexpected members in classes, traits, interfaces, or enums.
(Or to tolerate them for stubs for editors/IDEs)

Related to microsoft#395
TysonAndre added a commit to TysonAndre/tolerant-php-parser that referenced this pull request Dec 26, 2023
Using a class-like member in the wrong class-like is a compile-time
error, not a parsing error. Tolerate it and parse the current/remaining
statements and leave it to the applications to warn about using
unexpected members in classes, traits, interfaces, or enums.
(Or to tolerate them for stubs for editors/IDEs)

Related to microsoft#395
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

Successfully merging this pull request may close these issues.

None yet

3 participants