Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:124140 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 2B0D21A009C for ; Mon, 1 Jul 2024 13:15:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1719839812; bh=/6XsVI7unmxfwJZRmzmNJTjS71iodVA43EkmM8Ysha8=; h=In-Reply-To:References:Date:From:To:Subject:From; b=RYzzqaOLAh1MFtyp4vdJhvlGGPBgmRwGtK8CTYGibWOex7UzGrIGQl9iBJT0hJqtD Lx+Wh6MoD4xYT3vrH8x6SMARDFd74Zi+NTNPcxppGMnrDCbLWUa7RyZurVu0RvvpYn 4NKqidoQiLXvqpQan/VjhDfqD42FDeW1bEgs2dDsISY6EBKtj/i6pjxWjvU8IHR30n iAUGVUvwuAlZii4TqNQ6V3NrXgjZo3RsD00ptcC7s1MuRBJ6XClMxXJQaZm9Vcjg8p OjZgCCxYLxH6Q2ErILbD7tlguyOBjEYsccvrQ2XWdG2pvVIdnQSUWqn2LTiVUjRZRP +WrZHUawKRBiA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id CA76D1807BC for ; Mon, 1 Jul 2024 13:16:49 +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.1 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS,SPF_NONE,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 wfhigh7-smtp.messagingengine.com (wfhigh7-smtp.messagingengine.com [64.147.123.158]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 1 Jul 2024 13:16:47 +0000 (UTC) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfhigh.west.internal (Postfix) with ESMTP id 375C9180007D for ; Mon, 1 Jul 2024 09:15:26 -0400 (EDT) Received: from imap50 ([10.202.2.100]) by compute1.internal (MEProxy); Mon, 01 Jul 2024 09:15:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to; s=fm2; t=1719839725; x=1719926125; bh=pDlewua/BNH3VJqX7TC0Y ewvflMDqLdub7vnxi9pu4w=; b=IcySllSp9AOhalROA0Ms2OvpeJ4cLiGHgBpmf HeY0PrYDxzK35VI6mz2zKDo7o04CZysiHHcZewm17uu7gmDuGeslQ2qii2wtpq5t zOK2k5UunEvdpjWgOPNBByl/X+Qej/gLBgCGwApiph+VhQTJu5truqC3X5PxyXS6 WlB/Ju7MKZQ/qFWw2Saabu81/NcRPMpd2xa8en13uZNaM1Ki1sKnbhTeR5GC18gY 0gYHIvjP0ThL2GelR1Kou+Qzxxs+Q+3+L2qnfOAA+LFb4nP/ZU/Hackdr8cDSVDt riwx5cgx43l7qjbsSBLYeIO+mWjPMLmGH9Vz3xqXJitOqbtZg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1719839725; x= 1719926125; bh=pDlewua/BNH3VJqX7TC0YewvflMDqLdub7vnxi9pu4w=; b=E zXAhMB1V5MaEMfumi+BpB58FkqnYR1GzuTcDfq5c8VizDVaTO536ZParLec5UNB3 pL4c90dvG9doPkDMhyT9SJrLvJamShUgpsVLOW3e4V4bcT5fS+EgaJV2Li3t+PFS yUcY6H2OBokEQtmh+NAkCZARmOEGbd540qQoRt4F/wWv3l+NmfSe2wbvyDUeJwCo wGU8SzOfEs2JUJVkt5B/zrEENFG9zuPgjb3kSDjg5sucoPtqRd22JL5QQvSzFz2J napfaZCMo/ichxb7/bcUnVAVm/YySbDUmxpKS8Uj5yFRsSv0LzR1zRj4fPbhCNz1 m7D/CVj8HPltL1iBvjY4Q== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudefgdeiudcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefofgggkfgjfhffhffvufgtgfesthhqredtreerjeenucfhrhhomhepfdfnrghr rhihucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtoh hmqeenucggtffrrghtthgvrhhnpefhkedtfffghfekieduhedvheefgfefheeugfdvleet teektefgteejieeltdelkeenucffohhmrghinhepghhithhhuhgsrdgtohhmnecuvehluh hsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheplhgrrhhrhiesghgr rhhfihgvlhguthgvtghhrdgtohhm X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 6964C1700093; Mon, 1 Jul 2024 09:15:25 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.11.0-alpha0-566-g3812ddbbc-fm-20240627.001-g3812ddbb Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 Message-ID: In-Reply-To: References: <07A8534A-1B45-4F15-A78B-AA7DDF92B8B6@koalephant.com> <5BA404A4-7281-475F-A1F6-D1252ABB059D@miles.systems> Date: Mon, 01 Jul 2024 13:14:41 +0000 To: "php internals" Subject: Re: [PHP-DEV] [Initial Feedback] Typed Arrays Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable From: larry@garfieldtech.com ("Larry Garfield") On Mon, Jul 1, 2024, at 12:21 PM, Richard Miles wrote: > Howdy Rob, > >>> I appreciate your feedback, and I think it=E2=80=99s valid. I try to= compare my expectations to what is possible in typescript. >>=20 >> I feel like Typescript is the wrong model to follow. The type system = in Typescript is Turing Complete (https://github.com/microsoft/TypeScrip= t/issues/14833) and php barely has a type system. It doesn=E2=80=99t eve= n have consistent type checking, for that matter (properties are checked= differently than arguments which are checked differently than construct= or arguments =E2=80=94 and the fact they agree with each other at all, i= s interesting, because they don=E2=80=99t arrive at the same conclusions= in the same way. I=E2=80=99ve been dealing with subtle bugs here for we= eks on an unannounced RFC implementation) and this is why generics is a = can of worms: implementing it would essentially force a rewrite of the t= ype system into a proper type system. >>=20 >> In my honest opinion, before we can even have this type of conversati= on, we need to have an RFC about the syntax (there may already be one, I= haven=E2=80=99t checked =E2=80=94 and internet is spotty where I curren= tly am). The pattern matching RFC was proposed as though it would be wri= tten one way, people have thrown out ideas of different syntax, but I do= n=E2=80=99t think there is an =E2=80=9Cofficial=E2=80=9D syntax. A good = starting point may be to simply propose an RFC about syntax so future RF= Cs can be consistent.=20 >>=20 >> =E2=80=94 Rob > > I actually did not know it was turning complete, very interesting!=20 > While it is easy for anyone to say, =E2=80=98we're not even close to=20 > typescript,=E2=80=99=20 > that=E2=80=99s precisely what brings me to the table. I would be happy= with us=20 > just voting on syntax. It seems like past RFC=E2=80=99s only=20 > ever got hung up on generics (wrongfully?). I want to work on=20 > implementing generics, too, after this. I feel this is probably a good=20 > stepping stone.=20 > > A vote would solidify the following: > > > interface iArrayA ['a' =3D> string ] > interface iArrayB extends iArrayA ['b' =3D> string, 'c' =3D> ?string, = =E2=80=98d=E2=80=99=20 > =3D> SomeClass, =E2=80=98e=E2=80=99=3D> iArrayA, =E2=80=98f=E2=80=99= =3D> mixed ] > $array =3D (iArrayA &| iArrayB) [ =E2=80=98a=E2=80=99 =3D> =E2=80=98he= llo=E2=80=99 ]; > > > That would allow us to move into an implementation discussion, which i= s=20 > also absolutely needed.=20 > > Best,=20 > Richard Miles As Stephen already said, we have this already. It's spelled like this: class A { public function __construct(public string $a) {} } class B extends A { public function __construct( public string $a,=20 public string $b,=20 public ?string $c, public SomeClass $d, public A $e, mixed $f, ) {} } If you know the keys at code time, use a class, not an array. Full stop= , period, end of story. Using an array as a record object in PHP >=3D 7= *is wrong*. It's slower, more memory-intensive, less ergonomic, harder= to debug, harder to statically analyze, harder to learn, harder to use.= If you're still doing that, it's past time to stop. If your legacy ap= plication from the PHP 3 days is still doing that, it's past time to upg= rade it. So new language features to make "misuse arrays as objects" easier are a= ctively counter-productive. A Dict / Hashmap is appropriate when you do *not* know the keys in advan= ce, and thus cannot use a pre-defined object for it. There are plenty o= f use cases for that, but in that case, all you need type-wise is the ke= y type and value type, because all entries should be of the same type (g= ive or take inheritance). Mixing in random other types... is wrong. Th= at's the whole reason why people keep talking about collections/typed ar= rays/generics. So the "array interface" syntax you keep posting is actively counter-pro= ductive. --Larry Garfield