Re: [RFC] Type Aliases
| From: | Rob Landers | Date: | Wed, 03 Dec 2025 21:09:02 +0000 |
| Subject: | Re: [RFC] Type Aliases | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-129530@lists.php.net to get a copy of this message | ||
On Wed, Dec 3, 2025, at 22:04, Paul M. Jones wrote:
> Hi Rob,
>
> (We've been using a lot of PHPStan type aliasing lately in the Star-Interop work, so this
> topic is timely.)
>
> Is there some possibility of making the aliases more classlike so they can be autoloaded? A la:
>
> namespace Foo;
> type number { as int|float; }
>
> Then elsewhere:
>
> use Foo\number;
> function sum(number $a, number $b): number { return $a + $b; }
>
> Let me know if I've missed something fundamental.
>
>
> -- pmj
They fundamentally cannot be autoloaded because autoloading happens at runtime, not compile time. At
least, with the current autoloader. Autoloading type aliases would need to have a fundamentally
different type of autoloading that doesn’t exist today.
— Rob