Literal types RFC
| From: | Bogdan Ungureanu | Date: | Sun, 04 Oct 2020 23:38:01 +0000 |
| Subject: | Literal types RFC | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-111996@lists.php.net to get a copy of this message | ||
Hello internals,
Since union types have landed in PHP, this allows us the possibility to
have literal types support as well and I would like to hear your
thoughts about an RFC for it.
I think a feature like this would greatly improve the way we model our code
in very common use cases. For example, let's consider having a function
that returns the status of a post.
```php
/**
/** @return "draft"|"published"
*/
function getStatus(): string { }
```
Would become
```php
function getStatus(): "draft" | "published" { }
```
Of course this could become quite messy if there are more than a few
literal types, in which case separate RFCs could be created for type
aliases and valueof/keyof features.
I would also like to mention that I also worked on a basic implementation
for the first phase of the implementation; it's nowhere near to be
completed, but I think I can finish it with some guidance/help from you.
Regards,
Bogdan Ungureanu