-
Notifications
You must be signed in to change notification settings - Fork 7.8k
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
RFC: Support Closures in constant expressions #16458
Conversation
May I suggest automatically making Closures in constants static? (just the same like if you were to declare some closure without I realize though that for properties we should require static for now. (unless you are going to provide properties with $this on |
8b31603
to
a75d04c
Compare
@bwoebi It does not look like top-level closures are implicitly static:
Independent of that, I would value the explicitness of needing to specify the
Yes. I already had a quick chat with @iluuu1994 about this and we agreed that requiring the closure to be static would be a good decision for the initial version of this feature. |
@TimWolla Oh, yes, there's a difference between static and unbound. But is there any reason a top-level closure should not be unbound?
The only problem is with Closures within classes. |
I assume that would technically be supportable in the exact locations where a
I believe that the usefulness of a top-level closure is very limited (why would you not write a regular function?). For my initial proposal I want to keep the feature easy to reason about (“closures in const-expressions must always be static”) and also keep the implementation simple(r). |
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.
The patch looks good. I don't see problems, but I can't think about all possible consequences.
c534e21
to
bc01615
Compare
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.
It looks like zend_ast_get_lineno()
lacks handling for ZEND_AST_OP_ARRAY
.
Couldn't find any other issues.
Indeed it does. It appears to be unobservable as of now, since |
I missed this yesterday, but it seems you're missing support for file cache in ext/opcache/zend_file_cache.c. The rest LGTM. |
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 see no more issues.
469df0e
to
bc0539b
Compare
RFC: https://wiki.php.net/rfc/closures_in_const_expr Co-authored-by: Volker Dusch <volker@tideways-gmbh.com> Co-authored-by: Ilija Tovilo <ilija.tovilo@me.com> Co-authored-by: Arthur Kurbidaev <artkurbidaev@gmail.com>
bc0539b
to
609de12
Compare
Most notably this allows to use Closures as Attribute parameters.
RFC: https://wiki.php.net/rfc/closures_in_const_expr