fix(preprocessor): enforce Zend enum declaration rules - #61
Open
AlessioGiacobbe wants to merge 2 commits into
Open
fix(preprocessor): enforce Zend enum declaration rules#61AlessioGiacobbe wants to merge 2 commits into
AlessioGiacobbe wants to merge 2 commits into
Conversation
Zend rejects at compile time, and TypePHP previously accepted silently:
- properties in enums (instance, static, hooked): enum class entries
have no property table ("Enum E cannot include properties")
- magic methods other than __call/__callStatic/__invoke ("Enum E
cannot include magic method __x"); the banned set was probed one by
one against Zend 8.4.13
- a case value on a non-backed enum and a missing value on a backed
enum ("Case A of ... enum E must (not) have a value")
- duplicate case names and case/const name collisions: enum cases are
class constants ("Cannot redefine class constant E::A")
- a backing type other than int|string
- explicitly implementing UnitEnum/BackedEnum, which Zend adds itself
("cannot implement previously implemented interface"), including the
non-backed-enum BackedEnum variant
- abstract methods in enum bodies: an enum can never be abstract
Enum ClassDef flags now carry Modifiers::FINAL, mirroring ZEND_ACC_FINAL
on enum class entries, so `class B extends E` is rejected by the
existing final-class inheritance check without touching the Translator.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Enum declaration rules were entirely unenforced — all of these compiled (each a Zend compile fatal, probed for the exact rule and message): properties in enums; the forbidden magic-method set (__construct, __destruct, __clone, __get/__set/__unset/__isset, __sleep/__wakeup, __set_state, __serialize/__unserialize, __toString, __debugInfo — the full set probed one by one; __call/__callStatic/__invoke stay legal); a case with a value in a non-backed enum and a case without one in a backed enum; duplicate case names and case/const clashes; backing types other than int|string; explicit
implements UnitEnum/BackedEnum; abstract methods in enum bodies.Enum ClassDef flags now also carry FINAL (mirroring ZEND_ACC_FINAL on enum class entries), so
class B extends SomeEnumis rejected by the existing final-class check with Zend's own wording, and final-class devirtualization legitimately applies to enums.Deliberately not added, because Zend evaluates them lazily at runtime: case-value/backing-type mismatches and duplicate case values.
Part of the split of #39.