-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[PHP 7.4] Add arrow function #602
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need feedback on this. I'm not sure the ArrowFunction should inherit FunctionLike - because ArrowFunction has exactly 1 statement, not more.
I think it should. We can construct an equivalent statement array for the expression, and code should be able to treat arrow functions just like other functions then.
Thank you! Ready for 2nd feedback |
On running parser test: <?php
fn($a) => $a; with:
I get error:
The grammar file is somehow wrong, not sure how. |
I resolved all the comments, ready to review |
What needs to be done here? I need this feature so I can add and test migration path in Rector. |
7.4 and nightly builds are green now. We should update the used php-src archive to make the 7.2 build also pass. |
Is that part of |
@TomasVotruba Yes. https://github.com/nikic/PHP-Parser/blob/master/test_old/run-php-src.sh needs to be changed to fetch a 7.4 archive instead. |
I see, just a sec 👍 Recently I've also noticed "The return keyword can be omitted" in https://stitcher.io/blog/short-closures-in-php Is that true? $ids = array_map(fn(Post $post): int => $post->id, $posts);
$ids = array_map(fn(Post $post): return int => $post->id, $posts); If so, I shall add test case for that |
No, adding a return is not allowed there. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, some final comments...
I was trying to rebase pull-request to merge the fixup! commits, but I keep failing on so many conflicts. Could you merge it locally or squash to one commit on merge? |
Merged as squash. Thanks for your work on this! Next up: https://wiki.php.net/rfc/spread_operator_for_array has been accepted :) |
Awesome 👍
Gimme a sec 😆 |
This PR based on PR to php-src: php/php-src#3941
Current RFC voting is 33:5, so if nothing complicated happens in implementation, this feature will get accepted to PHP 7.4.
I need feedback on this. I'm not sure the
ArrowFunction
should inheritFunctionLike
- becauseArrowFunction
has exactly 1 statement, not more.FunctionLike
be parrent to the new interface?Closure
?I tried to mimic php-src grammar
Zend/zend_language_parser.y