[RFC] Type Aliases
| From: | Rob Landers | Date: | Tue, 02 Dec 2025 22:23:06 +0000 |
| Subject: | [RFC] Type Aliases | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-129518@lists.php.net to get a copy of this message | ||
Hello Internals,
I’d like to request your comments on type aliases (not to be confused with typedefs) at https://wiki.php.net/rfc/typed-aliases
TL;DR (it’s actually rather short):
Following the same syntax as other use'ing statements, you can alias a type:
use type int|float as Number;
function sum(Number $a, Number $b): Number { return $a + $b; }
You can also include types, with some restrictions:
include types 'math-types.php';
function sum(Number $a, Number $b): Number { return $a + $b; }
These are compile-time replacements that serve to make code more readable and reduce repetition with
no runtime overhead. Type aliases follow the same scoping rules as other use imports.
— Rob