Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:124129 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id 254681A009C for ; Mon, 1 Jul 2024 06:01:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1719813792; bh=CDG12Q7tS1dJGjgry5C2sJG5nxnTFrgkdBjOhsz7rXE=; h=From:Subject:Date:In-Reply-To:Cc:To:References:From; b=QK78L70IR6YB8ZtqIK0LNX5tC9SDudYq6CmNf1HoEOz3WZ7MZTGevFYhfBX3UzfiW Unx0VovE7cSLmVb30XsPd9q2svCUb2SRPWovV4Io2S7wrFRPIoW7Bh57ISJ0ypezNp 4/ne5/FBcaq+YPaZBAUAFYc0DcC05R7AlmY/iHQn0XMyjgGrL98jrXPRBXIlYJ09G7 /FI/6FmCa/CNc+av+37WKNBsRM692LWl+upaM16pafyhUuCPFSkXQLebyG+1nkwEpz ALtu5p4qQ79EYjGWvDJfJ6t9f/SkC0GFbjjTofe5HtWzPzr075HjE2D1WzQdw4tCSP zcPJbzxsdQp+A== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 38A421807FE for ; Mon, 1 Jul 2024 06:03:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,DMARC_MISSING, HTML_MESSAGE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from mail1.25mail.st (mail1.25mail.st [206.123.115.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 1 Jul 2024 06:03:10 +0000 (UTC) Received: from smtpclient.apple (unknown [49.48.245.197]) by mail1.25mail.st (Postfix) with ESMTPSA id 8EF9C60458; Mon, 1 Jul 2024 06:01:44 +0000 (UTC) Message-ID: Content-Type: multipart/alternative; boundary="Apple-Mail=_9EF8128A-6D17-40D5-8ADF-BD7BA8BA818C" Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3774.600.62\)) Subject: Re: [PHP-DEV] [Initial Feedback] Typed Arrays Date: Mon, 1 Jul 2024 13:01:30 +0700 In-Reply-To: <5BA404A4-7281-475F-A1F6-D1252ABB059D@miles.systems> Cc: php internals To: Richard Miles References: <07A8534A-1B45-4F15-A78B-AA7DDF92B8B6@koalephant.com> <5BA404A4-7281-475F-A1F6-D1252ABB059D@miles.systems> X-Mailer: Apple Mail (2.3774.600.62) From: php-lists@koalephant.com (Stephen Reay) --Apple-Mail=_9EF8128A-6D17-40D5-8ADF-BD7BA8BA818C Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On 1 Jul 2024, at 10:05, Richard Miles wrote: >=20 > Howdy Stephen,=20 >=20 >>> It seems like everyone always gets really hung up on generics! That = or how to syntactically implement this. >>=20 >> Hi >>=20 >> 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' =3D> string]" syntax = is meant to be?) >>=20 >> 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. >=20 >=20 > I appreciate your feedback, and I think it=E2=80=99s 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.=20 >=20 > While it=E2=80=99s true that PHP can take arrays and mash them into = objects, I have to ask myself if this other language has this=20 > feature, why don't we? Is it because we don=E2=80=99t care? Is it a = bad feature? I don't think so.=20 > I have a PR for WebSockets that integrates with Apache. Why hasn=E2=80=99= t it been done before? > I don=E2=80=99t think this is an oversight on others, but rather, the = community is what makes PHP better, challenging norms.=20 >=20 > I=E2=80=99m not saying it will outperform what objectiveness currently = provides, but I'm also not saying it won=E2=80=99t! I don=E2=80=99t = think there=E2=80=99s a negative to=20 > me implementing this syntax, and who knows, maybe it will be awesome = for performance. I think what we should consider is that other=20 > languages have this, and I feel the community wants this but is hung = up on generics, which may have been an oversight.? I=E2=80=99m pretty = new=20 > here, and I=E2=80=99d love to make a meaningful impact, so the fact = that this idea has been brought up before is encouraging.=20 >=20 > Take, for example: >=20 > interface iArrayA ['a' =3D> string, 'b' =3D> string, 'c' =3D> ?string, = =E2=80=98d=E2=80=99 =3D> SomeClass, =E2=80=98e=E2=80=99=3D> iArrayA, = =E2=80=98f=E2=80=99 =3D> mixed ] >=20 > $a =3D new Dict;=20 >=20 >=20 > Maybe the signature for Dict is: >=20 > class Dict {} >=20 > Everyone harps on Generics, but no one can say how I'm supposed to = model iArrayA if we focus on Generics.=20 > We cannot safely define this now, as iArrayA is not a valid interface. = I believe that is what I'm advocating for alone. =20 > Array interfaces.=20 >=20 > Best,=20 > 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=20 --Apple-Mail=_9EF8128A-6D17-40D5-8ADF-BD7BA8BA818C Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8

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' =3D> 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=E2=80=99s 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=E2=80=99s 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=E2=80=99t care? Is it a bad feature? I don't think = so. 
I have a PR for WebSockets that integrates with = Apache. Why hasn=E2=80=99t it been done before?
I don=E2=80=99t = think this is an oversight on others, but rather, the community is what = makes PHP better, challenging = norms. 

I=E2=80=99m not saying it will = outperform what objectiveness currently provides, but I'm also not = saying it won=E2=80=99t! I don=E2=80=99t think there=E2=80=99s 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=E2=80=99m pretty new 
here, and = I=E2=80=99d 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' =3D> string, 'b' =3D> string, 'c' = =3D> ?string, =E2=80=98d=E2=80=99 =3D>  SomeClass, = =E2=80=98e=E2=80=99=3D>  iArrayA, =E2=80=98f=E2=80=99 =3D> = mixed ]

$a =3D 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 



= --Apple-Mail=_9EF8128A-6D17-40D5-8ADF-BD7BA8BA818C--