I really like the idea and I would love to see it in PHP. I'm wondering
however, what would be the scope of the feature and how complex would be
designed type system. Examples I saw in this thread could be easily
replaced with union and intersection types (i.e. numeric as int|float). In
my opinion, there is a little benefit implementing in this shape making the
PHP core more complex.
The two use cases of user defined types in PHP which would benefit a lot
IMO, would be:
1. Typed arrays similar to Typescript.
2. Semantic types which would increase the security of systems. Example:
type UserId = int;
function setUserId_1(int $userId){}
function setUserId_2(UserId $userId){}
setUserId_1(5); // OK
setUserId_2(5); // TypeError
setUserId_1(UserId(5)); // OK
setUserId_2(UserId(5)); // OK
Kind regards,
Jorg