Re: [PHP-DEV] Basic Type Alias

2023-10-30 Thread Larry Garfield
On Sun, Oct 29, 2023, at 9:52 PM, Jorg Sowa wrote: > 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

Re: [PHP-DEV] Basic Type Alias

2023-10-29 Thread Jorg Sowa
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

Re: [PHP-DEV] Basic Type Alias

2023-10-28 Thread Rowan Tommins
On 26 October 2023 23:35:56 BST, Deleu wrote: >I would love it if we could bring up a discussion on proposing changes to >the PHP Namespace system to allow for something more like ESM while >considering we don't have a build system and a hot-reload system, but I'm >just not sure if PHP Type

Re: [PHP-DEV] Basic Type Alias

2023-10-27 Thread Mike Schinkel
> On Oct 26, 2023, at 3:23 PM, Larry Garfield wrote: > > App-wide aliases run into the autoloading problem. If the engine runs across > the add() function above, and "numeric" isn't defined, what can it do? > Currently, all it can do is trigger autoloading, which only works for > class-ish

Re: [PHP-DEV] Basic Type Alias

2023-10-27 Thread Robert Landers
Why are we reinventing alias syntax? We already have "use" to alias per file: use My\Namespace\MyFancyType as MyNewFancyType; use string|int|bool as MyFancyType; Further, in PHP we specify a type using a colon, not an equal sign, thus this feels more idiomatic to PHP (and less ambiguous): type

Re: [PHP-DEV] Basic Type Alias

2023-10-27 Thread Claude Pache
> Le 26 oct. 2023 à 21:23, Larry Garfield a écrit : > > App-wide aliases run into the autoloading problem. If the engine runs across > the add() function above, and "numeric" isn't defined, what can it do? > Currently, all it can do is trigger autoloading, which only works for > class-ish

Re: [PHP-DEV] Basic Type Alias

2023-10-26 Thread Oladoyinbo Vincent
Since there may be need for reusability, I feel it can have this kind of structure: // File: A.php ``` namespace A; typedef TypeLists { type Msg = string|null; type Numeric = int|float; type MyClass = \Package\Test|\Package\Db; } ``` // file: B.php ```

Re: [PHP-DEV] Basic Type Alias

2023-10-26 Thread Erick de Azevedo Lima
I'll use it a lot if they'll be namespaced. It avoids name-collision using the existing ecosystem and we already use lots of "uses" in our codes. When Enums came to the party, they came namespaced as traits, classes and interfaces. The last 2 represent types, concrete and abstract. User defined

Re: [PHP-DEV] Basic Type Alias

2023-10-26 Thread Deleu
On Thu, Oct 26, 2023 at 4:23 PM Larry Garfield wrote: > On Thu, Oct 26, 2023, at 6:37 AM, Oladoyinbo Vincent wrote: > > App-wide aliases run into the autoloading problem. If the engine runs > across the add() function above, and "numeric" isn't defined, what can it > do? Currently, all it can

Re: [PHP-DEV] Basic Type Alias

2023-10-26 Thread Larry Garfield
On Thu, Oct 26, 2023, at 6:37 AM, Oladoyinbo Vincent wrote: > Greetings to you all, > > I will like to submit an RFC on introducing type alias to php. > > Even though Generics won't or never be introduced to PHP, personally i will > like php to add the type alias feature. > > Type aliases provide

Re: [PHP-DEV] Basic Type Alias

2023-10-26 Thread Marc
Hi, On 26.10.23 08:37, Oladoyinbo Vincent wrote: Greetings to you all, I will like to submit an RFC on introducing type alias to php. Even though Generics won't or never be introduced to PHP, personally i will like php to add the type alias feature. Type aliases provide a mechanism to create

Re: [PHP-DEV] Basic Type Alias

2023-10-26 Thread Aleksander Machniak
On 26.10.2023 08:37, Oladoyinbo Vincent wrote: type MyType = string|null; function greetings(MyType $message): string { // Implementation } greetings(1); // TypeError When writing RFC you'd have to decide/clarify whether you want this to be an error in strict_types mode only or not.

Re: [PHP-DEV] Basic Type Alias

2023-10-26 Thread Lanre Waju
I would like to voice my support for this and i'm willing to help with the implementation. As for differentiating between type aliases and classnames, only one of them can be instantiated. Lanre On 2023-10-26 12:37 a.m., Oladoyinbo Vincent wrote: Greetings to you all, I will like to submit

Re: [PHP-DEV] Basic Type Alias

2023-10-26 Thread Lanre Waju
Hi Saki, I will have to disagree as the convenience doesn't come from the complexity of union types, rather how many times its used. Its easier to use ConstantNode in 10 functions vs NodeA|NodeB|NodeC. On 2023-10-26 6:58 a.m., Saki Takamachi wrote: Hi, It seems to me that there is more to

Re: [PHP-DEV] Basic Type Alias

2023-10-26 Thread Saki Takamachi
Hi, It seems to me that there is more to lose than gain. I'm afraid that when we look at the signature, we'll be confused as to whether it's a class or a type. Even if these problems were successfully resolved, I feel that it would only reduce readability. I've never seen a union type complex

Re: [PHP-DEV] Basic Type Alias

2023-10-26 Thread Robert Landers
On Thu, Oct 26, 2023 at 8:37 AM Oladoyinbo Vincent wrote: > > Greetings to you all, > > I will like to submit an RFC on introducing type alias to php. > > Even though Generics won't or never be introduced to PHP, personally i will > like php to add the type alias feature. > > Type aliases provide

[PHP-DEV] Basic Type Alias

2023-10-26 Thread Oladoyinbo Vincent
Greetings to you all, I will like to submit an RFC on introducing type alias to php. Even though Generics won't or never be introduced to PHP, personally i will like php to add the type alias feature. Type aliases provide a mechanism to create more descriptive and readable type hints in PHP