-
Notifications
You must be signed in to change notification settings - Fork 7.9k
static $var = xxx
should support any expression
#8959
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
Comments
No. That has been explicitly excluded from the "new in initializers" RFC:
See the "Order of evaluation" section to get some insight why supporting arbitrary expressions might not be a good idea, or at the very least needs careful consideration. |
Thank you for pointing to the RFC. It seems the RFC actually claims it will be allowed :), citing:
It seems you meant "new expressions in (static and non-static) property initializers and class constant initializers". But this issue is about "static variable initializers". The "Order of evaluation" section clearly discuss when "static variable initializers" will be evaluated:
So I belive this does not require a new RFC and could be maybe even considered as a bug. |
|
I see. The issue is not that a In the RFC there is one example:
What is the reason behind this decision? Unclear order of evaluation when using a reflection? For
so the usecase from this issue description should be supported and probably no RFC should be required, IMHO there is no ambiguity, as it is more or less syntactic sugar to https://3v4l.org/G1EiN. |
Making I expect the largest complication would be the existence of |
There has not been any recent activity in this feature request. It will automatically be closed in 14 days if no further action is taken. Please see https://github.com/probot/stale#is-closing-stale-issues-really-a-good-idea to understand why we auto-close stale feature requests. |
dear stale bot, it will be fixed by #9301 :) |
This wasn't closed automatically because of the manual merging. I'll close it now. |
Description
https://3v4l.org/gTufh
https://3v4l.org/G1EiN - this works,
static $var
can hold an object, only the initial value declaration needs longer codeCurrently php emits fatal error for
static $var = new class() {};
.But
static $var = ...;
should support any expression like if the assign op would not be prefixed withstatic
as such prefix only defines the statement should be evaluated only once per php request lifecycle & the variable kept alive.It seems like some historical php limitation...
Instead of a fatal error, I expect this result for the test case above:
The text was updated successfully, but these errors were encountered: