Re: Basic Type Alias

From: Date: Sun, 29 Oct 2023 21:52:50 +0000
Subject: Re: Basic Type Alias
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-121517@lists.php.net to get a copy of this message
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

« previous php.internals (#121517) next »