php-parser icon indicating copy to clipboard operation
php-parser copied to clipboard

Add PHP 8 Support / WIP

Open ichiriac opened this issue 5 years ago • 28 comments

Prepare the parser to PHP 8 :

  • [x] https://wiki.php.net/rfc/union_types_v2

Work In Progress as RFC are not yet closed

ichiriac avatar Jan 19 '20 17:01 ichiriac

https://wiki.php.net/rfc/nullsafe_operator

What is the status about php 8 support?

Selion05 avatar Jan 10 '21 12:01 Selion05

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

Wulfheart avatar Feb 05 '21 23:02 Wulfheart

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.

cseufert avatar Mar 22 '21 12:03 cseufert

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 :)

czosel avatar Mar 24 '21 09:03 czosel

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.

cseufert avatar Mar 24 '21 10:03 cseufert

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 :-)

czosel avatar Mar 24 '21 16:03 czosel

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

eldair avatar Jun 18 '21 11:06 eldair

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) { }

MasonD avatar Aug 12 '21 04:08 MasonD

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

cseufert avatar Aug 16 '21 00:08 cseufert

I also noticed that there seems to be a small issue with Attributes that contain bitwise operators: image

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 avatar Nov 01 '21 17:11 jaulz

@jaulz I think a separate issue would be better - thanks!

czosel avatar Nov 01 '21 17:11 czosel

@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?

jaulz avatar Nov 02 '21 07:11 jaulz

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.

czosel avatar Nov 02 '21 07:11 czosel

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.

jaulz avatar Nov 02 '21 08:11 jaulz

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.

ichiriac avatar Nov 10 '21 16:11 ichiriac

Hi, any progress on PHP8 support?

yaegassy avatar Dec 07 '21 15:12 yaegassy

Further improvements to PHP8 support landed in 3.1.0-beta.6 :tada:

czosel avatar May 22 '22 20:05 czosel

I'd say we could slowly promote the current 3.1.0 release to stable, would you agree? @MaartenStaa @cseufert

czosel avatar Jul 02 '22 18:07 czosel

I'd say we could slowly promote the current 3.1.0 release 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.

MaartenStaa avatar Jul 07 '22 19:07 MaartenStaa

👍 enjoy your holiday! 🏝

czosel avatar Jul 07 '22 20:07 czosel

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?

cseufert avatar Jul 12 '22 00:07 cseufert

@czosel @cseufert @MaartenStaa

Fixed #968.

Are you ready to release 3.1.0 already?

ytetsuro avatar Aug 09 '22 13:08 ytetsuro

I’d say we are, I’ll do it soon :-)

czosel avatar Aug 09 '22 21:08 czosel

Released v3.1.0 :tada:

czosel avatar Aug 10 '22 20:08 czosel

You guys are champions. Thank you for your work maintaining this package!

briangrider avatar Sep 07 '22 13:09 briangrider

am not sure if this is still in WIP or not, but i have the latest release and i still cant read property promotion 😢

ctf0 avatar Dec 14 '22 14:12 ctf0

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!

czosel avatar Dec 15 '22 08:12 czosel