You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
AllowDynamicProperties validation should error on enums #15731
<?php
#[AllowDynamicProperties]
enum Example {
case MyCase;
}
$c = Example::MyCase;
$c->prop = 'foo';
Resulted in this output:
Fatal error: Uncaught Error: Cannot create dynamic property Example::$prop in /in/Aqipu:9
Stack trace:
#0 {main}
thrown in /in/Aqipu on line 9
Process exited with code 255.
But I expected this output instead:
Fatal error: Cannot apply #[AllowDynamicProperties] to enum in /in/Aqipu on line 4
Process exited with code 255.
The change looks good on its own but I'm wondering whether it isn't an oversight of the enum RFC that attributes targeting classes are allowed for enums? It looks like to me that we should(n't have) allow(ed) this, so the best course of action would be to add a new target for enums, and only allow the usage if it's set.
Sent #15756 - wasn't sure if this is needed for UPGRADING since the error messages will be very clear, and since it hasn't been reported by anyone else unlikely to affect people, so I just put it in NEWS
Activity
DanielEScherzer commentedon Sep 3, 2024
See 3v4l https://3v4l.org/Aqipu - if enumerations can never have dynamic properties (as per https://www.php.net/manual/en/language.enumerations.object-differences.php) then we should prevent the dynamic properties attribute from being applied, since its presence generally indicates that it is safe to use dynamic properties
devnexen commentedon Sep 3, 2024
seems fair point (and easy enough to fix) @iluuu1994 your thoughts ?
kocsismate commentedon Sep 4, 2024
I've already shared my POV in the relevant PR:
#15733 (comment)
Fix GH-15731: Prevent `#[AllowDynamicProperties]` on enums (#15733)
DanielEScherzer commentedon Sep 4, 2024
@devnexen should this be added to
NEWSorUPGRADINGsince previously the attribute would be allowed, just not useful?devnexen commentedon Sep 4, 2024
can you make a PR ? I ll merge it.
Update NEWS for phpGH-15731
DanielEScherzer commentedon Sep 4, 2024
Sent #15756 - wasn't sure if this is needed for
UPGRADINGsince the error messages will be very clear, and since it hasn't been reported by anyone else unlikely to affect people, so I just put it inNEWS[skip ci] update NEWS for GH-15731 (#15756)