Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125220 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 0E6041A00BD for ; Sun, 25 Aug 2024 15:55:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1724601423; bh=kBNol8PdtuARRZNZJ1oMY0CtG8EAhcW6zjdOXMo+j8U=; h=Date:From:To:In-Reply-To:References:Subject:From; b=L/9H4S6Qpi/BDOAVQxooq/6yCrT5AvWdGy6HaE2rD1C0zAfgV8NSd65RiKtOk0m53 8HOhIcUphnZFaBNypvsbaR5eGDNPSidZhpO/js8c9ZbVUpjPjN1Y0Kcqw/QacwFjnr lAcrTRLEOYUsFPEaTxcBOT4vM4DfxMDB8jFNfQk4B14y4UEVYMA8JFhdT9DQ/0TjwX BU38Efx4aozW8ZWUcipNp7C5rTpjp7nwnh9n9FsKri+DMk4CPLZDPS3hK+ItYxI/n4 onwqy1BsrljpjC0y5yhFM6w5KDLoMawxCPXTa03/lcVIIQ9k0etClmP+eSHfWquA5Z y2jkryC9pIrFg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 312B1180079 for ; Sun, 25 Aug 2024 15:57:03 +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 autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from fout1-smtp.messagingengine.com (fout1-smtp.messagingengine.com [103.168.172.144]) (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 ; Sun, 25 Aug 2024 15:57:02 +0000 (UTC) Received: from phl-compute-03.internal (phl-compute-03.nyi.internal [10.202.2.43]) by mailfout.nyi.internal (Postfix) with ESMTP id 02C55138A055 for ; Sun, 25 Aug 2024 11:55:10 -0400 (EDT) Received: from phl-imap-09 ([10.202.2.99]) by phl-compute-03.internal (MEProxy); Sun, 25 Aug 2024 11:55:10 -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=fm2; t=1724601309; x=1724687709; bh=MLyyAXWEuD nZUPnnIry1nn+C29KufFG0sxYKk92YEx0=; b=Two6rQPaS3PtMy/eYaUA90AmQV eWiCFXMn+qGMQNPAOB7fdKhqu95YISvBgdJ0PJS/5qWH+m7imWFAujxkZ2VWVZK6 YDiT3JXHvqYkTEAizwCOqkstOPJhAV77nXb1LZEHJbhyRHQuV12C3tcxseSUZPBY 9HCoja2HnVk8q6cgR+A7q2LpNy/FBZPfQvGdQSQ+rWl2iSsVIQ+a0qXc41OQZqSj G/u2QaJT9kzoGapKOTa+Cb71Y3fpV3Bcvr9qUAhvYZne9fz5L8pB4RFa58c3nphw YkgRvpJ2CpFfz3x63ruY+Y2PxrPtWrLoUsjTiGW6C5kNuOxwd4FSvPH59gpg== 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= fm1; t=1724601309; x=1724687709; bh=MLyyAXWEuDnZUPnnIry1nn+C29Ku fFG0sxYKk92YEx0=; b=QizrUiRm9uxu+Hg9qwvxiZB35SHWW+jF+9Yjc2U2Fjp6 zIhbmiuQdtANBW0QXtKL1yriZOk51VKUG1r+glgHE+4aM4eWJTkNUumu0gPFU71m F6PE/8CmeSEHGO9CBrCkGWB/EzOrstIaNcVH76VQwSmv/XvoVxlzOdHn4wSplz3B NWhQNFYVhXIvm1qZPWt+lJHT9b2hQmG3wV1MgMyc1zVUx7HIsAxbbQAOEFKVvCcF 9asD9d2qVOWdk67A4m3nrhVVvGD2jKCJ84ALV0CvzyCet2hA9vKQEbHBD1jR17x4 3TZjDY1WYjmqHOQM5O9oAb179tPjEpVA7n13HdMAeg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddviedgleefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefoggffhf fvkfgjfhfutgesrgdtreerredtjeenucfhrhhomhepfdftohgsucfnrghnuggvrhhsfdcu oehrohgssegsohhtthhlvggurdgtohguvghsqeenucggtffrrghtthgvrhhnpedtueejtd ethfeulefhtdelieduteelffdtudelheffgedtieehhfelieejgfevgeenucevlhhushht vghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehrohgssegsohhtthhlvg gurdgtohguvghspdhnsggprhgtphhtthhopedupdhmohguvgepshhmthhpohhuthdprhgt phhtthhopehinhhtvghrnhgrlhhssehlihhsthhsrdhphhhprdhnvght X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id B954A780065; Sun, 25 Aug 2024 11:55:09 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 Date: Sun, 25 Aug 2024 17:54:48 +0200 To: internals@lists.php.net Message-ID: <4dad8898-b6d3-4b1b-aa7c-bd8385857f11@app.fastmail.com> In-Reply-To: References: <0c8ed5d6-5507-4c41-8d7f-05d14ba8aa4c@scriptfusion.com> <0cfd3a28-3cb0-4478-85fb-cf086d8e5c66@app.fastmail.com> Subject: Re: [PHP-DEV] [RFC] Default expression Content-Type: multipart/alternative; boundary=9722f6cc65404543a9bc6ca629deee85 From: rob@bottled.codes ("Rob Landers") --9722f6cc65404543a9bc6ca629deee85 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Sun, Aug 25, 2024, at 17:31, Rowan Tommins [IMSoP] wrote: > On 25/08/2024 14:35, Larry Garfield wrote: >> My other concern is the list of supported expression types. I=20 >> understand how the implementation would naturally make all of those=20 >> syntactically valid, but it seems many of them, if not most, are=20 >> semantically nonsensical. >=20 >=20 > I tend to agree with Larry and John that the list of operators should = be restricted - we can always allow more in future, but restricting late= r is much harder. >=20 > A few rules that seem logical to me: >=20 > 1) The expression should be reasonably guaranteed to produce the same = type as the actual default. >=20 >=20 > - No casts > - No comparison operators, because they produce booleans from non-bool= ean input > - No "<=3D>". Technically, it has an integer result, but it's rare to = use it as one, rather than a kind of three-value boolean > - No "instanceof" > - No "empty" >=20 > 2) The expression should not have side effects (outside of exotic oper= ator overloads). >=20 >=20 > - No "include", "require", etc > - No "throw" > - No "print" > - Borderline, but I would also say no "clone" >=20 > 3) The expression should be passing additional information into the fu= nction, not pulling information out of it. The syntax shouldn't be a way= to write obfuscated reflection, or invert data flow from callee to call= er. >=20 >=20 > - No assignments. > - No ternaries with "default" on the left-hand side - "$foo ? $bar : d= efault" is acting on local knowledge, but "default ? $foo : $bar" is act= ing on information the caller shouldn't know > - Same for "?:" and "??" > - No "match" with "default" as the condition or branch, for the same r= eason. "match($foo) { $bar =3D> default }" is fine, match(default) { ...= }" or "match($foo) { default =3D> ... }" are not. >=20 > Note that these can be seen as aspects of the same rule: the aim of th= e expression should be to transform the default value into another value= of the same type, not to pull it out and perform arbitrary operations b= ased on it. >=20 >=20 >=20 > I believe that leaves us with: >=20 >=20 > - Arithmetic operators: binary + - * / % **, unary + - > - Bitwise operators: & | ^ << >> ~ > - Boolean operators: && || and or xor ! > - Conditions with default on the RHS: $foo ? $bar : default, $foo ?: d= efault, $foo ?? default, match($foo) { $bar =3D> default } > - Parentheses: (((default))) >=20 >=20 >=20 > Even then, I look at that list and see more problems than use cases. A= s the RFC points out, library authors already worry about the maintenanc= e burden of named argument support, will they now also need to question = whether someone is relying on "default + 1" having some specific effect? >=20 > Maybe we should instead require justification for each addition: >=20 >=20 > - Bitwise | is nicely demonstrated in the RFC > - Bitwise & could probably be justified on similar grounds > - "$foo ? $bar : default" is discussed in the RFC > - The other "conditions with default on the RHS" in my shortlist above= fit the same basic use case >=20 > Beyond that, I'm struggling to think of meaningful uses: "whatever the= function sets as its default, do the opposite"; "whatever number the fu= nction sets as default, raise it to the power of 3"; etc. Again, they ca= n easily be added in later versions, if a use case is pointed out. >=20 >=20 >=20 > Regards, >=20 > --=20 > Rowan Tommins > [IMSoP] Hi Rowan, you went through a lot of trouble to write this out, and the r= easoning makes sense to me. However, all the nonsensical things you say = shouldn=E2=80=99t be allowed are already perfectly allowed today, you ju= st have to type a bunch of boilerplate reflection code. There is no new = behavior here, just new syntax.=20 =E2=80=94 Rob --9722f6cc65404543a9bc6ca629deee85 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable

=
On Sun, Aug 25, 2024, at 17:31, Rowan Tommins [IMSoP] wro= te:
On 25/08/2024 14:35, Larry Garfield=0A wrote:<= br>
My other concern is the list of suppo=
rted expression types.  I=20=0Aunderstand how the implementation would n=
aturally make all of those=20=0Asyntactically valid, but it seems many o=
f them, if not most, are=20=0Asemantically nonsensical.


I tend to agree with Larry and John that the list of= operators=0A should be restricted - we can always allow more in fu= ture, but=0A restricting later is much harder.

A few rule= s that seem logical to me:

1) The expression should be reasona= bly guaranteed to produce the=0A same type as the actual default.

- No casts
- No comparison operators, b= ecause they produce booleans from=0A non-boolean input
- No "<=3D>". Technically, it has an integer result, but it's=0A= rare to use it as one, rather than a kind of three-value boolean
- No "instanceof"
- No "empty"

=

2) The expression should not have side effects (outside of exotic= =0A operator overloads).

- No "include", "requir= e", etc
- No "throw"
- No "print"
- Borderline, but I would also say no "clone"

= 3) The expression should be passing additional information into=0A = the function, not pulling information out of it. The syntax=0A shou= ldn't be a way to write obfuscated reflection, or invert data=0A fl= ow from callee to caller.

- No assignments.
=
- No ternaries with "default" on the left-hand side - "$foo ? $bar= =0A : default" is acting on local knowledge, but "default ? $foo :=0A= $bar" is acting on information the caller shouldn't know
=
- Same for "?:" and "??"
- No "match" with "default= " as the condition or branch, for the=0A same reason. "match($foo) = { $bar =3D> default }" is fine,=0A match(default) { ... }" or "m= atch($foo) { default =3D> ... }" are=0A not.

= Note that these can be seen as aspects of the same rule: the aim=0A = of the expression should be to transform the default value into=0A = another value of the same type, not to pull it out and perform=0A = arbitrary operations based on it.


I believe that le= aves us with:

- Arithmetic operators: binary + - * / = % **, unary + -
- Bitwise operators: & | ^ << &= gt;>  ~
- Boolean operators: && || and or= xor !
- Conditions with default on the RHS: $foo ? $bar = : default, $foo=0A ?: default, $foo ?? default, match($foo) { $bar = =3D> default }
- Parentheses: (((default)))
<= p>


Even then, I look at that list and see more problems= than use=0A cases. As the RFC points out, library authors already = worry about=0A the maintenance burden of named argument support, wi= ll they now=0A also need to question whether someone is relying on = "default + 1"=0A having some specific effect?

Maybe we sh= ould instead require justification for each addition:

- Bitwise | is nicely demonstrated in the RFC
- Bitwise = & could probably be justified on similar grounds
- "$= foo ? $bar : default" is discussed in the RFC
- The other= "conditions with default on the RHS" in my shortlist=0A above fit = the same basic use case

Beyond that, I'm struggling t= o think of meaningful uses:=0A "whatever the function sets as its d= efault, do the opposite";=0A "whatever number the function sets as = default, raise it to the=0A power of 3"; etc. Again, they can easil= y be added in later=0A versions, if a use case is pointed out.
<= /p>


Regards,

--=20=0ARowan Tommins=0A[IMSoP]

Hi Rowan, you went through a lot of trouble to write this out, an= d the reasoning makes sense to me. However, all the nonsensical things y= ou say shouldn=E2=80=99t be allowed are already perfectly allowed today,= you just have to type a bunch of boilerplate reflection code. There is = no new behavior here, just new syntax. 

=E2=80=94 Rob
--9722f6cc65404543a9bc6ca629deee85--