Re: bikeshed: Typed Aliases
| From: | Larry Garfield | Date: | Sat, 07 Sep 2024 13:21:05 +0000 |
| Subject: | Re: bikeshed: Typed Aliases | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-125467@lists.php.net to get a copy of this message | ||
On Sat, Sep 7, 2024, at 7:42 AM, Mike Schinkel wrote:
>> On Sep 6, 2024, at 4:45 PM, Larry Garfield <larry@garfieldtech.com> wrote:
>> Aliases can then be used only in parameter, return, property, and instanceof types.
>> Extends and implements are out of scope entirely.
>
> Is there a strong technical reason why extends and implements should be
> out of scope?
>
> There is definite utility for this, to create a local alias in a
> namespace that can be used throughout the namespace rather than having
> to refer to the external namespace in many different places.
Because it quickly can produce nonsensical syntax.
class A {}
class B {}
typealias AB: A|B;
// This is logically nonsensical.
class C extends AB {}
While there are edge cases where that might be logical (if A and B are interfaces and &-ed
together, then it's kinda sorta the same as C implements A, B), separating those out and
allowing just that subset sounds like a lot of work for dubious gain, and introducing surprise
inconsistency. Better to just avoid that entirely.
--Larry Garfield