Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123842 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 CA24C1ADD37 for ; Tue, 25 Jun 2024 20:24:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1719347174; bh=dG+dixdivFGugnY5C/nUJHiHD5cqhBRNH9/lwHW7UTE=; h=In-Reply-To:References:Date:From:To:Subject:From; b=XnQZwDOVNh2m+7/6wHx44O94ofBjH9RjE+CBzF8LUVfVNEz6ktzgntWrfW4vLeF7u 2zcClp8iMLTHh4Mxx3toQnzS2+J+GxMYRBibHDmrB0jIR0fLigeeF+T68MMMU3mxde n+9JSISnP96WZhglTj8Kusuqwkx2r8hJU2d86qyLW7YteMozeNOB8eSAa2oZmkoria DBVnRv6R9lkzUzh2MtsUlQGuneQmL+MVaR71vS3YOzvZrKTzlvYpTBFDwR+1DlMuSE zqOHAECpIWS5/r77wv1TA/OzKF8nyddV0uQ5diYxwMT1h9KZM9imD8j6xK+KB8NJeu 2zH7651vvs2sw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id BCDA61804BB for ; Tue, 25 Jun 2024 20:26: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.1 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,HTML_MESSAGE, RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,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 fhigh2-smtp.messagingengine.com (fhigh2-smtp.messagingengine.com [103.168.172.153]) (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 ; Tue, 25 Jun 2024 20:26:09 +0000 (UTC) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfhigh.nyi.internal (Postfix) with ESMTP id A2ADC1140210 for ; Tue, 25 Jun 2024 16:24:52 -0400 (EDT) Received: from imap49 ([10.202.2.99]) by compute1.internal (MEProxy); Tue, 25 Jun 2024 16:24:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bottled.codes; h=cc: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=fm3; t=1719347092; x=1719433492; bh=eXd9i8GUXJ y2y2LGLUXK8Ajf2C0nu1dPPSJnFAAkdsA=; b=YqWHhJrq64rCH5iMMkegrbPDEF f1i60BMmkO5dHl7vHJnpr5mLLrTe8WtMe/HS8MMRSxufknklDrve4GP3UskNPoiz RIUKonnpfRZ2te2I5PdiaKSWQdg2O3OmcpvuuJkZjwPXJsHizZYHsbQXsmZQamCJ i9a9T2gnGu50OeHYw9gUmlJ/4Q/e2yWpFfbYcXAy2GgRhr65I9gu3boi9E1zGMv4 xfPHVjqnpsHl+Xf1wKq7z4oqpkhMfqKkO2+s4xBwo43fL8cjM/z4Xn34itokQcBy 3KwlAY7kpSp9cZOjkBKqOOYvsF/9gG94qibgCpEzZDsDlM1FE/JR35cNON4g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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=1719347092; x=1719433492; bh=eXd9i8GUXJy2y2LGLUXK8Ajf2C0n u1dPPSJnFAAkdsA=; b=VbtSa9thxOzjxqLFV5KdQuVE1OKv1/SqwqWt5Erijl9G 64JU3PBO48tFCCecAx7LGtol4iWQ8YyF8ON7LdrmKplgp/p7aezWd6FAXykdqRWy Ih26kDYpPRR469oyA73HKNRgpAWLu1YLzR+gNSwCrOk/kW+uMSe7J/y8DdxluHoq kD6MbQKbFJP47Xcpf2RQtfrT7jsCyoqcOqjk3jVjTI7SrDE6N+h4ENy3O5SAEI8k UlqS9q+eQ0Mupqt4y7C8RNvG264YFyizDHDsYqCkLwuUAIyBn3Wi0SyEPUJaNARy s8gHIbZueOx1QvdhYXtjQ2anY9wiyx2fP9kAChrlnA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrtddtgdduudeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefofgggkfgjfhffhffvufgtsegrtd erreerreejnecuhfhrohhmpedftfhosgcunfgrnhguvghrshdfuceorhhosgessghothht lhgvugdrtghouggvsheqnecuggftrfgrthhtvghrnhepfeefudfhudduieekkedugffhud fgleejgfekgefhvdeikeelvddvjeehteegteegnecuvehluhhsthgvrhfuihiivgeptden ucfrrghrrghmpehmrghilhhfrhhomheprhhosgessghothhtlhgvugdrtghouggvsh X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 5559215A0092; Tue, 25 Jun 2024 16:24:52 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.11.0-alpha0-538-g1508afaa2-fm-20240616.001-g1508afaa Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 Message-ID: In-Reply-To: References: <2a6b92eb-d5e9-4a1a-9548-a068ac42ebd2@app.fastmail.com> <1E295280-619B-4490-B53C-0899B64F9215@chaz.works> <97a93ae2-5202-47eb-bf51-ec1e976ea765@app.fastmail.com> Date: Tue, 25 Jun 2024 22:24:32 +0200 To: internals@lists.php.net Subject: Re: [PHP-DEV] [Early Feedback] Pattern matching Content-Type: multipart/alternative; boundary=dfb029247c304836a90178f1d881e6f5 From: rob@bottled.codes ("Rob Landers") --dfb029247c304836a90178f1d881e6f5 Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable On Tue, Jun 25, 2024, at 20:23, Ilija Tovilo wrote: > Hi Rob >=20 > On Tue, Jun 25, 2024 at 9:05=E2=80=AFAM Rob Landers wrote: > > > > On Tue, Jun 25, 2024, at 01:20, Ilija Tovilo wrote: > > > > On Mon, Jun 24, 2024 at 9:54=E2=80=AFPM Robert Landers wrote: > > > > > > To be honest, this is one of the smaller concerns I have with the = new > > > syntax. There might be some misunderstanding here, though. A > > > non-existent key is NULL, always has been, and always will be. > > > > This is just not accurate. Inexistent indexes are not null in PHP, > > they are undefined. PHP implicitly coerces undefined to null, because > > undefined is not a value accessible to users. The same occurs when > > accessing $undefinedVariable. For arrays, this fact is observable > > through `foreach`, warnings when accessing the index, and likely > > others. > > > > This is a bit like telling someone who fell off a ladder that they d= idn=E2=80=99t =E2=80=9Ctechnically=E2=80=9D fall, instead the Earth and = them pulled at each other until they collided and the ground + body abso= rbed the energy. > > > > While yes, you are =E2=80=9Ctechnically=E2=80=9D correct, what you d= escribe is essentially unobservable from the context of the running code= (unless you turn the warning into an error/exception). For all direct a= ccesses of array values ($arr['key']) an array is infinitely full of nul= ls (I have actually depended on this property at one point for a bloom f= ilter). >=20 > If null array values were indeed unobservable, then [] would be =3D=3D= =3D to > [null] (or at least =3D=3D), and a foreach over [null] would result in= 0 > iterations. But neither of those are the case. I think there is a difference between an empty array and a null, and tha= t is (hopefully) self-evident. I=E2=80=99m talking about the infinite nu= lls IN the array. You can write a for loop of all possible keys until th= e end of the universe, and all you will get is null. This is fairly easy= to prove. I'll wait... :p >=20 > > So yes, `[?'foo' =3D> string]` and `['foo' =3D> ?string]` are indeed > > different. The former accepts `[]`, while the latter accepts `['foo' > > =3D> null]`. > > > > Are they actually different in practice though? That was my point. A= fter the =E2=80=9Cis=E2=80=9D in both cases, you=E2=80=99ll have to use = null-coalescence to retrieve the value. For all intents, they are the sa= me resulting code. If you can show a difference in the resulting code an= d how it is an improvement, I may be inclined to agree, but I can=E2=80=99= t think of one. >=20 > Sure. If a null value were to mean "not set", then ['foo' =3D> string] > should accept ['foo' =3D> 'foo', 'bar' =3D> null], which is absolutely > observable if the code assumes it won't see any additional indexes. The only way you=E2=80=99d observe this (that I can think of) is by perf= orming a for-each loop over the array. In this case, I can't think of a = reason you would assert the shape of individual keys beforehand. Maybe s= omeone who would do that can chime in with a realistic example. What I was talking about is something like this: $hasFoo =3D $arr is [?'foo' =3D> string]; // if I understand the RFC correctly, $hasFoo is true for [] and ['foo' = =3D> 'some-string'] if ( $hasFoo ) { $foobar =3D $arr['foo'] ?? null; } Now with the alternative: $hasFoo =3D $arr is ['foo' =3D> ?string]; // in theory, this matches [], ['foo' =3D> null] and ['foo' =3D> 'some-s= tring'] if ( $hasFoo ) { $foobar =3D $arr['foo'] ?? null; } Note that the actual code *did NOT* change. What we have is that in the = first example, a person well-versed in PHP is going to wonder why `($has= Foo is false) =3D=3D=3D true` and `($arr['foo'] is null) =3D=3D=3D true`= . It's logically inconsistent with itself because we clearly specified t= hat it shouldn't exist but it does exist and the value is NULL. Yeah, it's weird that arrays are infinitely full of null, but surprising= ly useful. If we don't like it, we can always create an RFC to treat non= -existent keys as an error instead of a warning. =20 >=20 > Ilija >=20 =E2=80=94 Rob --dfb029247c304836a90178f1d881e6f5 Content-Type: text/html;charset=utf-8 Content-Transfer-Encoding: quoted-printable
On Tue, Ju= n 25, 2024, at 20:23, Ilija Tovilo wrote:
Hi Rob

On Tu= e, Jun 25, 2024 at 9:05=E2=80=AFAM Rob Landers <rob@bottled.codes> wrote:
>
<= /div>
> On Tue, Jun 25, 2024, at 01:20, Ilija Tovilo wrote:
>
> On Mon, Jun 24, 2024 at 9:54=E2=80=AFPM= Robert Landers <landers.= robert@gmail.com> wrote:
> >
&g= t; > To be honest, this is one of the smaller concerns I have with th= e new
> > syntax. There might be some misunderstandi= ng here, though. A
> > non-existent key is NULL, alw= ays has been, and always will be.
>
> = This is just not accurate. Inexistent indexes are not null in PHP,
> they are undefined. PHP implicitly coerces undefined to nu= ll, because
> undefined is not a value accessible to us= ers. The same occurs when
> accessing $undefinedVariabl= e. For arrays, this fact is observable
> through `forea= ch`, warnings when accessing the index, and likely
> ot= hers.
>
> This is a bit like telling s= omeone who fell off a ladder that they didn=E2=80=99t =E2=80=9Ctechnical= ly=E2=80=9D fall, instead the Earth and them pulled at each other until = they collided and the ground + body absorbed the energy.
&= gt;
> While yes, you are =E2=80=9Ctechnically=E2=80=9D = correct, what you describe is essentially unobservable from the context = of the running code (unless you turn the warning into an error/exception= ). For all direct accesses of array values ($arr['key']) an array is inf= initely full of nulls (I have actually depended on this property at one = point for a bloom filter).

If null array va= lues were indeed unobservable, then [] would be =3D=3D=3D to
[null] (or at least =3D=3D), and a foreach over [null] would result i= n 0
iterations. But neither of those are the case.

I think there is a difference between= an empty array and a null, and that is (hopefully) self-evident. I=E2=80= =99m talking about the infinite nulls IN the array. You can write a for = loop of all possible keys until the end of the universe, and all you wil= l get is null. This is fairly easy to prove. I'll wait... :p


> So yes, `[?'foo' =3D> string]` and `['foo' =3D> ?stri= ng]` are indeed
> different. The former accepts `[]`, w= hile the latter accepts `['foo'
> =3D> null]`.
>
> Are they actually different in practice= though? That was my point. After the =E2=80=9Cis=E2=80=9D in both cases= , you=E2=80=99ll have to use null-coalescence to retrieve the value. For= all intents, they are the same resulting code. If you can show a differ= ence in the resulting code and how it is an improvement, I may be inclin= ed to agree, but I can=E2=80=99t think of one.

<= div>Sure. If a null value were to mean "not set", then ['foo' =3D> st= ring]
should accept ['foo' =3D> 'foo', 'bar' =3D> nu= ll], which is absolutely
observable if the code assumes it= won't see any additional indexes.

=
The only way you=E2=80=99d observe this (that I can think of) is by= performing a for-each loop over the array. In this case, I can't think = of a reason you would assert the shape of individual keys beforehand. Ma= ybe someone who would do that can chime in with a realistic example.
=

What I was talking about is something like thi= s:

$hasFoo =3D $arr is [?'foo' =3D> stri= ng];

// if I understand the RFC correctly, = $hasFoo is true for [] and ['foo' =3D> 'some-string']
if ( = $hasFoo ) {
  $foobar =3D $arr['foo'] ?? null;
}

Now with the alternative:

$hasFoo =3D $arr is ['foo' =3D> ?string];

// in theory, this matches [], ['foo' =3D> nu= ll] and ['foo' =3D> 'some-string']
if ( $hasFoo ) {
=
  $foobar =3D $arr['foo'] ?? null;
}

Note that the actual code did NOT ch= ange. What we have is that in the first example, a person well-versed in= PHP is going to wonder why `($hasFoo is false) =3D=3D=3D true` and `($a= rr['foo'] is null) =3D=3D=3D true`. It's logically inconsistent with its= elf because we clearly specified that it shouldn't exist but it does exi= st and the value is NULL.

Yeah, it's weird = that arrays are infinitely full of null, but surprisingly useful. If we = don't like it, we can always create an RFC to treat non-existent keys as= an error instead of a warning.
  


Il= ija


=E2=80=94 Rob
--dfb029247c304836a90178f1d881e6f5--