PHP 8.4 Support: new MyClass()->method() without parentheses#8117
Merged
junichi11 merged 7 commits intoapache:masterfrom Jan 8, 2025
Merged
PHP 8.4 Support: new MyClass()->method() without parentheses#8117junichi11 merged 7 commits intoapache:masterfrom
junichi11 merged 7 commits intoapache:masterfrom
Conversation
- apache#8035 - https://wiki.php.net/rfc#php_84 - https://wiki.php.net/todo/php84 - Add PHP 8.4 - Fix the available periods
- apache#8035 - https://wiki.php.net/rfc#php_84 - https://wiki.php.net/rfc/new_without_parentheses - Fix the gramar file(`ASTPHP5Parser.cup`) - Add the `PHP84UnhandledError` - Add unit tests for the parser Example: ```php new Example()->method(); new $class()?->method(); new Example()::staticMethod1()::CONSTANT; new (trim(' Example '))()::staticMethod1()->field; new Example()::{'CONSTANT'}; new Example()(); new $class()(); new Example()['key']; new $class()['key']; new (trim(' Example '))()['key']; // anonymous classes echo new class { const CONSTANT = 'constant'; }::CONSTANT; new class { public function method() {} }->method(); new class () implements ArrayAccess { }['key']; ```
- apache#8035 - https://wiki.php.net/rfc#php_84 - https://wiki.php.net/rfc/new_without_parentheses - Fix the formatter - Add `Other` to spaces within parentheses option e.g. `($a + $b);`, `new (trim(' Example '))()->field;` - Add/Fix unit tests
- apache#8035 - https://wiki.php.net/rfc#php_84 - https://wiki.php.net/rfc/new_without_parentheses - Fix "Go to Declaration" & "Mark Occurrences" - Add unit tests
- apache#8035 - https://wiki.php.net/rfc#php_84 - https://wiki.php.net/rfc/new_without_parentheses - Fix the `UnusedVariableHint` - Add a unit test
- apache#8035 - https://wiki.php.net/rfc#php_84 - https://wiki.php.net/rfc/new_without_parentheses - Fix Code Completion feature - Add unit tests Note: The following case is not supported yet. The statement is broken. (it has a syntax error.) So, the anonymous class is not parsed correctly. i.e. We can't get members. We have to sanitize an error part. ```php echo new class() { public const string CONSTANT = "constant"; }::^ ```
- apache#8035 - https://wiki.php.net/rfc#php_84 - https://wiki.php.net/rfc/new_without_parentheses - Add a unit test for the navigator
junichi11
commented
Jan 6, 2025
|
|
||
| throw $instance->createException(); | ||
| throw ( $instance->createException()); | ||
| throw ($instance->createException()); |
junichi11
commented
Jan 6, 2025
| // for code completion | ||
| // e.g. new class() {}:: | ||
| // PHP Parse error: syntax error, unexpected token ";", expecting identifier or variable or "{" or "$" | ||
| parser.syntax_error(); |
Member
Author
There was a problem hiding this comment.
Add an error because this case is a syntax error.
junichi11
commented
Jan 6, 2025
Comment on lines
+476
to
+483
| // TODO: add tests for typing anonymous class without ";" | ||
| // e.g. | ||
| // echo new class() { | ||
| // public const string CONSTANT = "constant"; | ||
| // }::^ | ||
| // in the above case, the statement is broken (it has a syntax error) | ||
| // so, the anonymous class is not parsed correctly i.e. we can't get members | ||
| // we have to sanitize an error part |
Member
Author
There was a problem hiding this comment.
I didn't fix this because it's so hard/difficult to fix it.
Member
Author
|
@tmysik Most of the files that were added are unit tests. Sorry for the huge change. |
tmysik
approved these changes
Jan 8, 2025
Member
tmysik
left a comment
There was a problem hiding this comment.
Nicely done, thanks a lot. Great to have all the unit tests.
Member
Author
|
@tmysik Thank you for your time! Merging. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PHP 8.4 Support: Add PHP 8.4 to the PhpVersion
new MyClass()->method() without parentheses (Part 1)
ASTPHP5Parser.cup)PHP84UnhandledErrorExample:
PHP 8.4
PHP 8.3
new MyClass()->method() without parentheses (Part 2)
Otherto spaces within parentheses option e.g.($a + $b);,new (trim(' Example '))()->field;new MyClass()->method() without parentheses (Part 3)
new MyClass()->method() without parentheses (Part 4)
UnusedVariableHintnew MyClass()->method() without parentheses (Part 5)
Note: The following case is not supported yet.
The statement is broken. (it has a syntax error.)
So, the anonymous class is not parsed correctly. i.e. We can't get members.
We have to sanitize an error part.
new MyClass()->method() without parentheses (Part 6)