Re: [RFC] [Discussion] Literal Scalar Types
| From: | Sarina Corrigan | Date: | Mon, 15 Jun 2026 17:19:54 +0000 |
| Subject: | Re: [RFC] [Discussion] Literal Scalar Types | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-131286@lists.php.net to get a copy of this message | ||
It may be worth mentioning that within the Pattern Matching RFC future
scope, and mentioned a couple times within the discussion thread for the
RFC, there is a similar proposal that would allow for this without using
specific literal types.
It's outlined in
https://github.com/Crell/php-rfcs/blob/master/pattern-matching/future.md
under "Parameter or return guards"
It would allow for:
```
function setLogLevel (string $level is 'debug' | 'info' | 'warning' |
'error'): void {}
```
Of course, I don't think that a potential future scope of an in-draft RFC
is reason to dismiss a more direct implementation of literal scalar types,
but it may be useful to compare other ways we could achieve the same
functionality. I personally find pattern matching within parameter/return
types more versatile while keeping direct typing system more simplified.
Specifically for a range feature that Ben Ramsey brought up, pattern
matching for parameters seems much more appropriate.
All that being said, I would gladly welcome literal scalar types.
On Sun, Jun 14, 2026, 21:24 Seifeddine Gmati <azjezz@carthage.software>
wrote:
> Hello Internals,
>
> I'd like to start the discussion on a new RFC adding literal scalar
> types to PHP.
>
> - RFC: https://wiki.php.net/rfc/literal_scalar_types
> - Implementation: https://github.com/php/php-src/pull/22314
>
> Thanks,
> Seifeddine.
>