rfc:enum_allow_static_properties
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:enum_allow_static_properties [2021/05/18 00:42] – tandre | rfc:enum_allow_static_properties [2021/06/16 03:29] (current) – tandre | ||
---|---|---|---|
Line 3: | Line 3: | ||
* Date: 2021-05-17 | * Date: 2021-05-17 | ||
* Author: Tyson Andre, < | * Author: Tyson Andre, < | ||
- | * Status: | + | * Status: |
* Implementation: | * Implementation: | ||
* First Published at: http:// | * First Published at: http:// | ||
Line 27: | Line 27: | ||
- [[https:// | - [[https:// | ||
- Keeping track of which enum case reflects the current state of a state machine or system | - Keeping track of which enum case reflects the current state of a state machine or system | ||
+ | |||
+ | E.g. for [[https:// | ||
+ | |||
+ | <code php> | ||
+ | // https:// | ||
+ | enum Sprite { | ||
+ | case FROG; | ||
+ | case LOG; | ||
+ | case GRASS; | ||
+ | case WATER; | ||
+ | // etc. | ||
+ | | ||
+ | /** @var array< | ||
+ | private static array $cache = []; | ||
+ | | ||
+ | public static function getImageData(SpriteArt $value): MyModule\ImageData { | ||
+ | $key = $value-> | ||
+ | if (!isset(self:: | ||
+ | self:: | ||
+ | } | ||
+ | return self:: | ||
+ | } | ||
+ | | ||
+ | // Called when is no longer used, the color scheme changed, etc. | ||
+ | public static function clearImageData(SpriteArt $value): void { | ||
+ | self:: | ||
+ | } | ||
+ | | ||
+ | // Slow operation: Read image data from disk and decode image data. | ||
+ | public static function loadImageData(): | ||
+ | // ... | ||
+ | } | ||
+ | } | ||
+ | </ | ||
For example, one way to represent fetching the current environment (of a known enumeration of environments) would be a static method on the environment enum itself. The environment instance is immutable, but the environment being loaded depends on a file. | For example, one way to represent fetching the current environment (of a known enumeration of environments) would be a static method on the environment enum itself. The environment instance is immutable, but the environment being loaded depends on a file. | ||
Line 146: | Line 180: | ||
===== Unaffected PHP Functionality ===== | ===== Unaffected PHP Functionality ===== | ||
Instance properties continue to be forbidden on enums. | Instance properties continue to be forbidden on enums. | ||
+ | |||
+ | PHP enums were already able to have instance and static methods. | ||
===== Discussion ===== | ===== Discussion ===== | ||
Line 206: | Line 242: | ||
- | ===== Proposed Voting Choices | + | ===== Vote ===== |
- | Yes/No, requiring a 2/3 majority | + | This is a Yes/ |
+ | |||
+ | Voting started on June 1, 2021 and ends on June 15, 2021 | ||
+ | <doodle title=" | ||
+ | * Yes | ||
+ | * No | ||
+ | </ | ||
===== References ===== | ===== References ===== | ||
https:// | https:// | ||
[[enumerations|enums RFC]] | [[enumerations|enums RFC]] |
rfc/enum_allow_static_properties.txt · Last modified: 2021/06/16 03:29 by tandre