> On 1 Jul 2024, at 10:05, Richard Miles <richard@miles.systems> 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

Hi Richard,

To be clear I'm not really suggesting "mash arrays into objects". I'm saying 
that with the advent of constructor property promotion, property types, 
readonly properties, property hooks, etc, there's much less reason (and IMO 
much less developer desire) to use a "hash" (associative array) in PHP in the 
first place.  Classes (and the instances of them) with typed properties seem 
like a much more common solution to that problem, in my view. That they can be 
created from an associative array using argument unpacking (aka the splat 
operator) is a side benefit that facilitates working with legacy code (which is 
often full of associative arrays) IMO.

What a class with properties and all the modern niceties *can't* 
(ergonomically) do, is provide a *list* of objects of a given type - which is 
exactly what the `arrayof` (aka Type[]) syntax would give us.


Cheers

Stephen 




Reply via email to