Re: [RFC] Enumerations
| From: | Mike Schinkel | Date: | Wed, 09 Dec 2020 20:44:14 +0000 |
| Subject: | Re: [RFC] Enumerations | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-112479@lists.php.net to get a copy of this message | ||
> On Dec 9, 2020, at 3:29 PM, Benjamin Morel <benjamin.morel@gmail.com> wrote:
>
> On Wed, 9 Dec 2020 at 19:48, Mike Schinkel <mike@newclarity.net
> <mailto:mike@newclarity.net>> wrote:
>
> 5. Someone else mentioned shortcut syntax, which I would like to mention again, although I
> realize implement details might make this a non-starter.
>
> So if I have a function that accepts a Size from above, e.g.:
>
> function show(Size $size) {}
>
> Then it would be great if we could call the function like this since its parameter was
> type-hinted:
>
> show(::Medium)
>
> Rather than always having to write:
>
> show(Size::Medium)
>
> So can we consider a shortcut syntax?
>
> I'm not sure what value a shortcut syntax would bring, but it would surely break, or at
> least make ambiguous, union types:
>
> function show(Enum1|Enum2 $value) {}
> show(::Medium)
>
> Which enum would Medium resolve to?
Good question.
What *could* happen is:
1. It could resolve to the Enum that has a ::Medium,
2. Or it could be disallowed for union type hints (probably the better option as adding a
"Medium" to the other enum could inadvertently break code that calls it.)
3. This suggestion could just be tabled.
Again, I am just asking if this is something we could consider because it would be nice to shorten
line length in cases where expressions get really long.
Maybe a different question could be if a "use" statement could empower making explicit
shorthands/aliases?
-Mike
P.S. I completely understand if either of these things are out of scope for this RFC.