Re: [Initial Feedback] Typed Arrays
| From: | Richard Miles | Date: | Mon, 01 Jul 2024 03:05:08 +0000 |
| Subject: | Re: [Initial Feedback] Typed Arrays | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-124126@lists.php.net to get a copy of this message | ||
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