On 15/06/2026 3:22 am, Seifeddine Gmati 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.

I mainly see the benefit here as being able to be more strict about what a function actually accepts and returns, in cases where a dedicated enum would be overkill.

Two things I'd like to understand better:

Does the RFC allow referencing constants in type positions, or only raw literal values?

```
function foo(STATUS_ACTIVE|STATUS_INACTIVE $sort): void {}
```

```
What about enum values? For example:

function bar(Status::Active->value $status): void {}
// or simply as
function bar(Status::Active $status): void {}
```

Also, I'm not really a fan of mixing literal types with unions.

```
function foo(int|'bar' $param): void {}
```

To me, mixing these makes it harder to reason about what a function actually accepts. The whole point of literal types is to be (more) precise but the moment you throw a wide type like int into the union, that precision goes out the window. If a function takes int|'bar', what does that really tell me? It feels like it defeats the purpose.

--
Regards,

Jordi Kroon

Reply via email to