Re: [RFC] Type Aliases
| From: | Paul M. Jones | Date: | Wed, 03 Dec 2025 21:13:50 +0000 |
| Subject: | Re: [RFC] Type Aliases | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-129531@lists.php.net to get a copy of this message | ||
> On Dec 3, 2025, at 15:09, Rob Landers <rob@bottled.codes> wrote:
>
> 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.
Got it; thanks for the clarification.
-- pmj