Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123849 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 675F01A009C for ; Tue, 25 Jun 2024 21:58:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1719352812; bh=8ULEihfHDoPrIxkY8f+gy6W5mjpJNBh3XLnr2wklRiA=; h=In-Reply-To:References:Date:From:To:Subject:From; b=FQwTQlz9fIvjgX89XfCrjQmpKj5AxBkJGR8NGGhr2OIlDCF3Y//HULK1v4t2VVl5Y +OmSTsRm7b779WwfMLtkF7t+kep5eM4xIJmbCNLakIbR4xoUe0ywfQ2UDmr+PDRNcf gdNIKNAC4BrVFLbmz7TrQXrK/2hpg8mha0DaKQEmo+fL3VBQFjPZPUr/XSIn6GOWrn at0bmqsKb9xiOR3cEcxChhiqGEPA9SbMZEt5LlIDGVfXtBMV3SJ5gTYKCAVnb/HlbZ jUHxagQ5o56ycbw3T1DbdT/ox+mf8896Bkg2/zhb4Xx2Q0ptY18cypNgb57HVzy3iB OVfy68uZOqjcg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 22993180773 for ; Tue, 25 Jun 2024 22:00:08 +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 fout6-smtp.messagingengine.com (fout6-smtp.messagingengine.com [103.168.172.149]) (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 22:00:05 +0000 (UTC) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfout.nyi.internal (Postfix) with ESMTP id 7230813801FF for ; Tue, 25 Jun 2024 17:58:48 -0400 (EDT) Received: from imap49 ([10.202.2.99]) by compute1.internal (MEProxy); Tue, 25 Jun 2024 17:58:48 -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=1719352728; x=1719439128; bh=8ULEihfHDo PrIxkY8f+gy6W5mjpJNBh3XLnr2wklRiA=; b=MDQ8VD32QjleumSFn2ZdiNzqH5 CYybr+oTQ1tEyvpeCKVgz6X+pj1Fda/V8xXdp9i6AjZdQoz01gCG+u8UAGQTgSQI FamU2iu+pSZl9fIsepfhYVSdLX1EAPrthwCZQ/17/NipccAKKIg4bARGGlPsW+6h mWEiBBGvxp/F9iEe0D38GByyJlaRAp84Qz784nNx7Z2YPenA3DTv/1OHnFHnKNz2 v2SdKGSQGOC7m7YNKq51JTOJBYl1s3ccAf6rIS7yXsUqX/jXaRCJqPZ/ZxaxunWx CBSqAdFNOGer0lVvhJrY7mLNwKBX45V3g29WazGJZiVBZI1f3bP8H0+dvDLg== 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=1719352728; x=1719439128; bh=8ULEihfHDoPrIxkY8f+gy6W5mjpJ NBh3XLnr2wklRiA=; b=CLUShYJBeGoWj0UdwVKAr8Wo1ocq3iB2lzO/M/cgQd1U IccI82v1HLPWiSo7GKJKzkkRMOAvyTtg/eLUmpcCTHPzo6HuGPYERMb4jeyBKsfV BGIIF8kcbub8epfVZvBYY3GKumZaNTvq/RyJF0gPNfJ6BuvKweXd34Lme7wTY4DB ru2iY5MbxUnWSVxGhR0CunK7fhbT2ZKUbcKTGA5CnjRubdNgp465qibGWXS0xKmI Au3ansCGfDBqLFDhvAtW+K2BGj//ocEdNsKrtB2YEAblciXzT/Ap4gEGZ4Qc3QMp HjKGsesNOn5Rg/14YBino6xCtS4B1yno74NNYnqopg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrtddugddtgecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepofgfggfkjghffffhvffutgesrgdtre erreerjeenucfhrhhomhepfdftohgsucfnrghnuggvrhhsfdcuoehrohgssegsohhtthhl vggurdgtohguvghsqeenucggtffrrghtthgvrhhnpeeffeduhfduudeikeekudfghfdugf eljefgkeeghfdvieekledvvdejheetgeetgeenucevlhhushhtvghrufhiiigvpedtnecu rfgrrhgrmhepmhgrihhlfhhrohhmpehrohgssegsohhtthhlvggurdgtohguvghs X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 1299F15A0092; Tue, 25 Jun 2024 17:58:47 -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: <10390963-0c2c-441a-bcce-20a0433948c5@app.fastmail.com> In-Reply-To: <78D0FFF7-3867-4D71-B0C0-FA23E5121C39@rwec.co.uk> References: <2a6b92eb-d5e9-4a1a-9548-a068ac42ebd2@app.fastmail.com> <1E295280-619B-4490-B53C-0899B64F9215@chaz.works> <97a93ae2-5202-47eb-bf51-ec1e976ea765@app.fastmail.com> <78D0FFF7-3867-4D71-B0C0-FA23E5121C39@rwec.co.uk> Date: Tue, 25 Jun 2024 23:58:26 +0200 To: internals@lists.php.net Subject: Re: [PHP-DEV] [Early Feedback] Pattern matching Content-Type: multipart/alternative; boundary=6cecdcee61174999bb83452431385b21 From: rob@bottled.codes ("Rob Landers") --6cecdcee61174999bb83452431385b21 Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable On Tue, Jun 25, 2024, at 23:10, Rowan Tommins [IMSoP] wrote: >=20 >=20 > On 25 June 2024 21:24:32 BST, Rob Landers wrote: > >The only way you=E2=80=99d observe this (that I can think of) is by p= erforming a for-each loop over the array.=20 >=20 > There are many ways you can observe the difference between an absent k= ey and a null value; here are just a handful off the top of my head:=20 >=20 > - array_key_exists() (that's literally its purpose!) > - array_keys() > - count() (if the array held "an infinite number of nulls", we should = return infinity for every array!) > - json_encode() > - print_r(), var_dump(), var_export() > - extract() >=20 > It may be questionable to give meaning to the difference in some of th= ese cases, but different it definitely is.=20 True, but I was mainly referring to what you would do after performing a= n 'is', in which case, you probably wouldn't be using any of those funct= ions, or if you needed to, then why do you need 'is'? Even with the=20 $hasFoo =3D $arr is [?'foo' =3D> string]; You still have to run array_key_exists() to determine whether the key ex= ists, which means you likely still need to figure out a default value, a= nd null-coalesce is perfect for that ... but then it just points out tha= t it isn't that useful of a check, and that it is inconsistent with itse= lf. If you are running array_keys(), then why bother performing an 'is' when= you should already know the structure=E2=80=94that's the entire point o= f it. If you are running a count(), this kind of goes back to the same t= hing, but I would think count() would be run on a collection of data rat= her than structured data. For json_encode, I could see something like this being a "final check" o= f some sort, but most people are likely json_encoding objects these days= . This might be a good use case for this syntax, but I feel like this is= the wrong way to solve the problem. print_r, var_dump, etc. are more or less debugging tools. At least, I've= never seen their output used for program execution. I could be wrong. extract() can go get crushed by an RFC :) but it does occasionally have = its usefulness. Even then, until PHP 9, an undefined variable will still= be null. >=20 >=20 > > If we don't like it, we can always create an RFC to treat non-existe= nt keys as an error instead of a warning. >=20 > I believe that is the explicit intention or desire of those who raised= it from Notice to Warning. It would certainly prevent some bugs where a= typo leads to the wrong key being accessed. >=20 > Personally, I'd like to see a few use cases catered for first, like $c= ounters[$key]++ and $groups[$key][] =3D $value; Perhaps by introducing s= ome equivalent of Python's "defaultdict". Because I do agree that the cu= rrent behaviour is useful sometimes (even if I disagree in how to descri= be it). I think arrays have their uses, but I'd rather see some purpose-built da= ta structures where you can fully take advantage of their performance pr= operties=E2=80=94things like linked lists, heaps, etc. Yeah, there's SPL= , but its interfaces are kind of a mess since you can use a queue like a= deque or a stack (which is just weird and might or might not have perfo= rmance implications), for example. >=20 >=20 > Regards, > Rowan Tommins > [IMSoP] >=20 =E2=80=94 Rob --6cecdcee61174999bb83452431385b21 Content-Type: text/html;charset=utf-8 Content-Transfer-Encoding: quoted-printable
On Tue, Jun 25,= 2024, at 23:10, Rowan Tommins [IMSoP] wrote:


On 25 Jun= e 2024 21:24:32 BST, Rob Landers <rob@bottled.codes> wrote:
>The only way you=E2= =80=99d observe this (that I can think of) is by performing a for-each l= oop over the array. 

There are many wa= ys you can observe the difference between an absent key and a null value= ; here are just a handful off the top of my head: 
- array_key_exists() (that's literally its purpose!)
- array_keys()
- count() (if the array held "an in= finite number of nulls", we should return infinity for every array!)
=
- json_encode()
- print_r(), var_dump(), var_ex= port()
- extract()

It may be = questionable to give meaning to the difference in some of these cases, b= ut different it definitely is. 

True, but I was mainly referring to what you would do after perfo= rming an 'is', in which case, you probably wouldn't be using any of thos= e functions, or if you needed to, then why do you need 'is'? Even with t= he 

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

You still have to run array_key_= exists() to determine whether the key exists, which means you likely sti= ll need to figure out a default value, and null-coalesce is perfect for = that ... but then it just points out that it isn't that useful of a chec= k, and that it is inconsistent with itself.

If = you are running array_keys(), then why bother performing an 'is' when yo= u should already know the structure=E2=80=94that's the entire point of i= t. If you are running a count(), this kind of goes back to the same thin= g, but I would think count() would be run on a collection of data rather= than structured data.

For json_encode, I c= ould see something like this being a "final check" of some sort, but mos= t people are likely json_encoding objects these days. This might be a go= od use case for this syntax, but I feel like this is the wrong way to so= lve the problem.

print_r, var_dump, etc. ar= e more or less debugging tools. At least, I've never seen their output u= sed for program execution. I could be wrong.

extract() can go get crushed by an RFC :) but it does occasionally hav= e its usefulness. Even then, until PHP 9, an undefined variable will sti= ll be null.



> If we don't like it, = we can always create an RFC to treat non-existent keys as an error inste= ad of a warning.

I believe that is the expl= icit intention or desire of those who raised it from Notice to Warning. = It would certainly prevent some bugs where a typo leads to the wrong key= being accessed.

Personally, I'd like to se= e a few use cases catered for first, like $counters[$key]++ and $groups[= $key][] =3D $value; Perhaps by introducing some equivalent of Python's "= defaultdict". Because I do agree that the current behaviour is useful so= metimes (even if I disagree in how to describe it).

I think arrays have their uses, but I'd rather see= some purpose-built data structures where you can fully take advantage o= f their performance properties=E2=80=94things like linked lists, heaps, = etc. Yeah, there's SPL, but its interfaces are kind of a mess since you = can use a queue like a deque or a stack (which is just weird and might o= r might not have performance implications), for example.

<= /div>

=
Regards,
Rowan Tommins
[IMSoP= ]


=E2=80=94 Rob
--6cecdcee61174999bb83452431385b21--