-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[RFC] Implement dynamic class const fetch #9793
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
Yes, I agree, but for consistency, all constant access should be able to isset/coalesced. I.e. also a trivial |
Nice, this was always a bit of a weird hole in our variable variable syntax.
That seems like an orthogonal change (not sure whether it's a good one). For the purposes of this proposal, the existing semantics should be followed, under which |
Suppressing errors would provide a direct counterpart for // PHP 8.2
$fqn = State::class . '::' . $stateName;
$result = defined($fqn) ? constant($fqn) : State::Default;
// Without ??
$fqn = State::class . '::' . $stateName;
$result = defined($fqn) ? State::{$stateName} : State::Default;
// WIth ??
$result = State::{$stateName} ?? State::Default; We have three obvious options:
Number 3 sounds undesirable at first but given that That said, I'm ok with starting with option 1. Relaxing it will always be easier than the opposite. |
I would prefer |
@iluuu1994 While it's certainly most useful that way, it might warrant two different RFCs, first a RFC for IS fetches on constants, then a RFC on dynamic class const fetch? |
e348735
to
d4c1c60
Compare
a7cd4dc
to
36db851
Compare
c02e1b1
to
e423774
Compare
e423774
to
5c4394d
Compare
5c4394d
to
355b515
Compare
https://wiki.php.net/rfc/dynamic_class_constant_fetch