> On Sep 6, 2024, at 4:45 PM, Larry Garfield <la...@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.

> On Sep 6, 2024, at 8:46 PM, Davey Shafik <da...@php.net> wrote:
> I would very much prefer to either go all in with an Enum-like (which means 
> that we can hang methods on to the value) or we need to distinguish between 
> type hints for class-likes and type hints for not-class-likes (*Bar anyone?).

Allowing methods also have definite value as most use-cases I have seen in 
other languages alias in order to add methods, especially for enabling support 
of interfaces.

Which, however, brings up an important distinction that other languages have 
made and which I think PHP would benefit from addressing:

1. Type Alias => Different Name for Same Type
2. Type Def => New Type which has all the same properties and methods of other 
type

e.g. (being hypothetical with the syntax; bikeshed away):

typealias  LocalWidget: Widget

typedef  MyWidget: Widget {
   function foo() {...}
}

function doSomething(Widget $widget) {...}

$w = new LocalWidget;
doSomething($w);           // This works, no problem as LocalWidget === Widget

$w = new MyWidget;
doSomething($w);           // This throws an error as MyWidget !== Widget

-Mike

Reply via email to