On Mon, Jul 1, 2024, at 05:05, Richard Miles wrote:
> Howdy Stephen, 
> 
>>> 
>>> 
>>> It seems like everyone always gets really hung up on generics! That or how 
>>> to syntactically implement this.
>> 
>> Hi
>> 
>> Given other improvements in the language, I don't really see much need for 
>> the ability to specify fixed keys and their types (ie associative arrays) (I 
>> assume that's what the "['a' => string]" syntax is meant to be?)
>> 
>> Is there some fundamental aspect of the original arrayof RFC that prevents 
>> it from being revived today? The whole "does it include nulls" part is moot 
>> now presumably because we have both ? And |null, and the Type[] syntax is 
>> very common in docblocks.
> 
> I appreciate your feedback, and I think it’s valid. I try to compare my 
> expectations to what is possible in typescript.
> This comparison, while not a perfect match, is a great source of learning and 
> inspiration. 
> 
> While it’s true that PHP can take arrays and mash them into objects, I have 
> to ask myself if this other language has this 
> feature, why don't we? Is it because we don’t care? Is it a bad feature? I 
> don't think so. 
> I have a PR for WebSockets that integrates with Apache. Why hasn’t it been 
> done before?
> I don’t think this is an oversight on others, but rather, the community is 
> what makes PHP better, challenging norms. 
> 
> I’m not saying it will outperform what objectiveness currently provides, but 
> I'm also not saying it won’t! I don’t think there’s a negative to 
> me implementing this syntax, and who knows, maybe it will be awesome for 
> performance. I think what we should consider is that other 
> languages have this, and I feel the community wants this but is hung up on 
> generics, which may have been an oversight.?  I’m pretty new 
> here, and I’d love to make a meaningful impact, so the fact that this idea 
> has been brought up before is encouraging. 
> 
> Take, for example:
> 
> interface iArrayA ['a' => string, 'b' => string, 'c' => ?string, ‘d’ =>  
> SomeClass, ‘e’=>  iArrayA, ‘f’ => mixed ]
> 
> $a = new Dict<string, iArrayA>; 
> 
> 
> Maybe the signature for Dict is:
> 
> class Dict<R is string | int, S is mixed> {}
> 
> Everyone harps on Generics, but no one can say how I'm supposed to model 
> iArrayA if we focus on Generics. 
> We cannot safely define this now, as iArrayA is not a valid interface. I 
> believe that is what I'm advocating for alone.  
> Array interfaces. 
> 
> Best, 
> Richard Miles

Hello,

> I appreciate your feedback, and I think it’s valid. I try to compare my 
> expectations to what is possible in typescript.

I feel like Typescript is the wrong model to follow. The type system in 
Typescript is Turing Complete 
(https://github.com/microsoft/TypeScript/issues/14833) and php barely has a 
type system. It doesn’t even have consistent type checking, for that matter 
(properties are checked differently than arguments which are checked 
differently than constructor arguments — and the fact they agree with each 
other at all, is interesting, because they don’t arrive at the same conclusions 
in the same way. I’ve been dealing with subtle bugs here for weeks on an 
unannounced RFC implementation) and this is why generics is a can of worms: 
implementing it would essentially force a rewrite of the type system into a 
proper type system.

In my honest opinion, before we can even have this type of conversation, we 
need to have an RFC about the syntax (there may already be one, I haven’t 
checked — and internet is spotty where I currently am). The pattern matching 
RFC was proposed as though it would be written one way, people have thrown out 
ideas of different syntax, but I don’t think there is an “official” syntax. A 
good starting point may be to simply propose an RFC about syntax so future RFCs 
can be consistent. 

— Rob

Reply via email to