php-parser
php-parser copied to clipboard
Add PHP 8 Support / WIP
Prepare the parser to PHP 8 :
- [x] https://wiki.php.net/rfc/union_types_v2
Work In Progress as RFC are not yet closed
https://wiki.php.net/rfc/nullsafe_operator
What is the status about php 8 support?
What’s new in PHP8?
- Named arguments
- Attributes
- Constructor property promotion
- Union types
- Match expression
- Nullsafe operator
I’d suggest creating an separate issue for each if these features.
Compiled from https://www.php.net/releases/8.0/en.php
There are now patches available for:
- named arguments #673
- property promotion c1 #697
- union types #656 (merged in php8 staging branch)
- match expression #686
- nullsafe operator #662 (merged in php8 staging branch)
so really the work just needs to focus on attributes, however I am not sure the right way to update the lexer to support Attributes.
Hi @cseufert
Awesome work! #662 has been merged in a temporary php8 branch because I don't know the codebase well enough to just merge stuff into master before @ichiriac took a look as well. If you like, you can point your PRs to the php8 branch as well, and I'll try to find some time for a first review :)
I have changed the following PR's to merge to the php8 branch:
- #686 Match expression
- #697 Promoted properties v2
I am going to have a go at getting this stuff working in prettier at some point, and am looking foward to having someone who know the codebase have a review of the code. I feel it could benefit a lot from being ported to typescript, but I guess thats a totally different problem.
Awesome! As I said before, reviews in the parser are also quite difficult for me - I'm more comfortable on the prettier side. Either way I'll try to do my best to help, it would be awesome to have full php8 support in the prettier plugin :-)
Hello,
There is no tracking for non-capturing catches - } catch (Exception) { Parse Error : syntax error, unexpected ')'
I created a pull request https://github.com/glayzzle/php-parser/pull/755
Is this the correct place to remark on an error I noticed with parsing of promoted constructor params? php-parser complains about a syntax error when a promoted constructor param is marked as nullable with a question mark
public function __construct(public ?string $nullable) { }
Is this the correct place to remark on an error I noticed with parsing of promoted constructor params? php-parser complains about a syntax error when a promoted constructor param is marked as nullable with a question mark
public function __construct(public ?string $nullable) { }
I have submitted a PR to fix this in the parser: https://github.com/glayzzle/php-parser/pull/785
I also noticed that there seems to be a small issue with Attributes that contain bitwise operators:

These lines cause the following error:
Error: Bad terminal sequence "|" at line 7 (offset 87)
at lexer.matchST_ATTRIBUTE (/foo/node_modules/php-parser/src/lexer/attribute.js:62:11)
at lexer.next (/foo/node_modules/php-parser/src/lexer.js:443:26)
at lexer.lex (/foo/node_modules/php-parser/src/lexer.js:363:20)
at lexer.lex (/foo/node_modules/php-parser/src/lexer.js:363:35)
at parser.lex (/foo/node_modules/php-parser/src/parser.js:627:29)
at parser.next (/foo/node_modules/php-parser/src/parser.js:556:8)
at parser.read_static_getter (/foo/node_modules/php-parser/src/parser/variable.js:99:12)
at parser.read_variable (/foo/node_modules/php-parser/src/parser/variable.js:80:21)
at parser.read_expr_item (/foo/node_modules/php-parser/src/parser/expr.js:421:19)
at parser.read_expr (/foo/node_modules/php-parser/src/parser/expr.js:18:19)
Shall I raise it as a separate issue or do you want to track it here?
@jaulz I think a separate issue would be better - thanks!
@czosel hm, I noticed that there is a pending issue and PR which talks about merging php8 features into main:
https://github.com/glayzzle/php-parser/issues/793
https://github.com/glayzzle/php-parser/pull/809
I am using [email protected] right now which already comes with some basic PHP8 features if I understand correctly. Should I rather wait for that before raising the issue?
Oh, I assumed that you were already working with the php8 branch - sorry! If not, there is a good chance that your issue has already been fixed inside the php8 branch - over the past month several larger features have been merged in this branch, but didn't land in master yet because we still needed the review from @ichiriac. I hope we'll soon be able to merge all of those back into master to avoid future confusion.
Okay, thanks for your quick feedback! 😊 In that case I will just wait for it and come back in case I still notice it afterwards.
Hi @czosel, I'll work on pending PR this week-end, if everything is ok then I'll release a new version and publish it on NPM.
Hi, any progress on PHP8 support?
Further improvements to PHP8 support landed in 3.1.0-beta.6 :tada:
I'd say we could slowly promote the current 3.1.0 release to stable, would you agree? @MaartenStaa @cseufert
I'd say we could slowly promote the current
3.1.0release to stable, would you agree? @MaartenStaa @cseufert
Yes, agreed. Would probably be good to fix #968 first, but things seem to be working well mostly.
I'm going on vacation two weeks as of tomorrow, so during that time I unfortunately won't have time to look at the linked issue.
👍 enjoy your holiday! 🏝
Yes, a 3.1.0 release makes sense to me, which can parse PHP <= 8.1.
It looks like PHP 8.2 has not added much that changes the syntax of the language. From what I can tell it is just the readonly class keyword for proper immutable classes. Is it worth getting this functionality integrated?
@czosel @cseufert @MaartenStaa
Fixed #968.
Are you ready to release 3.1.0 already?
I’d say we are, I’ll do it soon :-)
Released v3.1.0 :tada:
You guys are champions. Thank you for your work maintaining this package!
am not sure if this is still in WIP or not, but i have the latest release and i still cant read property promotion 😢
Hi @ctf0, support for promoted properties landed a while ago in #697. Feel free to open an issue with some details if something doesn’t work as expected!