Newsgroups: php.internals
Path: news.php.net
Xref: news.php.net php.internals:125217
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 7046E1ADB4E
	for <internals@lists.php.net>; Sun, 25 Aug 2024 15:29:17 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail;
	t=1724599869; bh=UAhFLbjEyoo3PegJYee7hRthdCHRxpspQH7PbE/9O44=;
	h=Date:Subject:To:References:From:In-Reply-To:From;
	b=NGVPDSuxFEsilRTb326TCuoGVecbzB20jHd2PxTuGORDqzLXWPJAFfml+fn7pziYV
	 etfIpqxccCref77TZmnT68DqXcjaeJ3p9sInGxDseMoO5v2f6L72T47sTHcW2wxWp4
	 46PUd6gP/4q5P/Ik+5pIQoLahPmHHktpuDlvyV1bWb9FebnFV5KcQRvsRx/LyZSf4y
	 42oHF9PtAxik3qYh1n2CczRA5DFh3ssqDMbNspYRt0X1FCcqU9Wyc4U4GvXpXvyH6M
	 20oaT5Cz85x+J8HDyRUYFEC7ZnQer+0z5MyGhjMB92EyKoNlQ7D+JTP+yZF98RCqnR
	 cEhctvClvQOng==
Received: from php-smtp4.php.net (localhost [127.0.0.1])
	by php-smtp4.php.net (Postfix) with ESMTP id 85F1A1801D5
	for <internals@lists.php.net>; Sun, 25 Aug 2024 15:31:06 +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,DKIM_SIGNED,
	DKIM_VALID,DMARC_MISSING,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,
	RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no
	autolearn_force=no version=4.0.0
X-Spam-Virus: No
X-Envelope-From: <bilge@scriptfusion.com>
Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.49])
	(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 <internals@lists.php.net>; Sun, 25 Aug 2024 15:31:03 +0000 (UTC)
Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-37196786139so2133956f8f.2
        for <internals@lists.php.net>; Sun, 25 Aug 2024 08:29:10 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=scriptfusion-com.20230601.gappssmtp.com; s=20230601; t=1724599750; x=1725204550; darn=lists.php.net;
        h=in-reply-to:from:content-language:references:to:subject:user-agent
         :mime-version:date:message-id:from:to:cc:subject:date:message-id
         :reply-to;
        bh=ZLfeXoU8HotsJ43x7fx24yThbNRcl+4C6zEw1b9Yyyg=;
        b=uzXzWPE9kut4OWZtPhv4D2aim8EJHN4Pz+KjobSve8mOxkFCK9xt8FBohfHhOfKNp2
         X6/IOfCkyUp9C4Kp+r/iTAMJOeVpcoMsCNIBwCIoDy9Qp8OLyFOXk8hbDSt1Fh/zPCFO
         /myW+Dt7ZwWqqOB99GQv4+vs35KL0v+r/oEf0Y5OpNFPN3nLLkSm7pgQr5w4IToaN9KI
         rpiUYWZiPzjFwS153LJqXza42CwHnubsehvSKaOLa8gWlpO0+7gclmzaYpTPgKM4F4UG
         Ki+m0rEc58DVwQVzCOkWYCC6vbosgedicYvemYwwWodKnOk1Zto4GDG/kK6Vp8821Frh
         qnpw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1724599750; x=1725204550;
        h=in-reply-to:from:content-language:references:to:subject:user-agent
         :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject
         :date:message-id:reply-to;
        bh=ZLfeXoU8HotsJ43x7fx24yThbNRcl+4C6zEw1b9Yyyg=;
        b=hJI2RKZ2LwzhBCMdkIyirgLshZsKBBImZb0NiCoAsUrJRL0MEC/KvDTlMOAprqtC9M
         B2uW65a85YRpLVU+EFCPc9F6JZjY5rdCB+jFN2FEuiO2dh16VfyiCm1RqhcHZv/rs6gB
         gub/a4xonan5bGBTDZBmywChPrXlPFuRhfXySlWjGiX6iN1rqxX2y4JBsisL5xfzFPxu
         UTf6cqyZ7CGtt9r5EdgCwwyVE3kXUvM6AHejn2kJ34UiaDA3v6Chw6QR/6YH/RPH4nMr
         upTVVYV8oMH0zveQ9271eVAjNaLtEkS4LPk3fekOCiyiG/9N/G6AcmNf67fakdO7DtjT
         3dww==
X-Gm-Message-State: AOJu0YxQv2dIleeyUUEjpXEWEKdooJyd+1koBYdgUsBqIG/BXd/HcYZG
	7YlAsdfYkiNEqvydqPSPyLu3icST6XXVjUY+SlMFc5F21YzTT6681EGpFjycfmcuaBYsVarqaAo
	C
X-Google-Smtp-Source: AGHT+IHJYkgZRfisO8qCuhY3yJIU4o6mNCLvbU95Ik1byxr8UmJjTYnqCOOn+00zfNX+qcxjOjFXMQ==
X-Received: by 2002:a05:6000:1951:b0:371:82ec:206f with SMTP id ffacd0b85a97d-373118650abmr4829298f8f.16.1724599749404;
        Sun, 25 Aug 2024 08:29:09 -0700 (PDT)
Received: from ?IPV6:2a01:4b00:bf09:5101:c4b4:d418:3b87:bff1? ([2a01:4b00:bf09:5101:c4b4:d418:3b87:bff1])
        by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-3730817ae1fsm8809659f8f.65.2024.08.25.08.29.08
        for <internals@lists.php.net>
        (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);
        Sun, 25 Aug 2024 08:29:09 -0700 (PDT)
Content-Type: multipart/alternative;
 boundary="------------2wPv3bob9k9LCHdNUo0CemYZ"
Message-ID: <3e0d031e-256f-47cd-9a2b-dcdc760f5498@scriptfusion.com>
Date: Sun, 25 Aug 2024 16:29:07 +0100
Precedence: bulk
list-help: <mailto:internals+help@lists.php.net
list-unsubscribe: <mailto:internals+unsubscribe@lists.php.net>
list-post: <mailto:internals@lists.php.net>
List-Id: internals.lists.php.net
x-ms-reactions: disallow
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Subject: Re: [PHP-DEV] [RFC] Default expression
To: internals@lists.php.net
References: <0c8ed5d6-5507-4c41-8d7f-05d14ba8aa4c@scriptfusion.com>
 <0cfd3a28-3cb0-4478-85fb-cf086d8e5c66@app.fastmail.com>
Content-Language: en-GB
In-Reply-To: <0cfd3a28-3cb0-4478-85fb-cf086d8e5c66@app.fastmail.com>
From: bilge@scriptfusion.com (Bilge)

This is a multi-part message in MIME format.
--------------2wPv3bob9k9LCHdNUo0CemYZ
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

On 25/08/2024 14:35, Larry Garfield wrote:
> The approach here seems reasonable overall.  The mental model I have from the RFC is "yoink the default value out of the function, drop it into this expression embedded in the function call, and let the chips fall where they may."  Is that about accurate?
Yes, as it happens. That is the approach we took, because the 
alternative would have been changing how values are sent to functions, 
which would have required a lot more changes to the engine with no clear 
benefit. Internally it literally calls the reflection API, but a 
low-level call, that elides the class instantiation and unnecessary 
hoops of the public interface that would just slow it down.
> My main holdup is the need.  I... can't recall ever having a situation where this is something I needed.  Some of the examples show valid use cases (eg, the "default plus this binary flag" example), but again, I've never actually run into that myself in practice.
That's fine. Not everyone will have such a need, and of those that do, 
I'm willing to bet it will be rare or uncommon at best. But for those 
times it is needed, the frequency by which it is needed in no way 
diminishes its usefulness.I rarely use `goto` but that doesn't mean we 
shouldn't have the feature.
> My other concern is the list of supported expression types.  I understand how the implementation would naturally make all of those syntactically valid, but it seems many of them, if not most, are semantically nonsensical.  Eg, `default > 1` would take a presumably numeric default value and output a boolean, which should really never be type compatible with the function being called.  (A param type of int|bool is a code smell at best, and a fatal waiting to happen at worst.)  In practice, I think a majority of those expressions would be logically nonsensical, so I wonder if it would be better to only allow a few reasonable ones and block the others, to keep people from thinking nonsensical code would do something useful.

Since you're not the only one raising this, I will address it, but just 
to say there is no good reason, in my mind, to ever prohibit the 
expressiveness. To quote Rob

 >I'm reasonably certain you can write nonsensical PHP without this 
feature. I don't think we should be the nanny of developers.

I fully agree with that sentiment. It seems to be biting me that I went 
to the trouble of listing out every permutation of what /expression/ 
means where perhaps this criticism would not have been levied at all had 
I chosen not to do so. Why does that matter? Because PHP already allows 
you to do many more ridiculous things, they're just not routinely 
presented to you so they're not part of your mind map. The end-user 
documentation will also not mention the nonsense cases, so the average 
developer will not think of them. You can write, `include(1 + 1);`, 
because `include()` accepts an expression. You will get: "Failed opening 
'2' for inclusion". Should we restrict that? No, because that's just how 
expressions work in any context where they're allowed. Special-casing 
the T_DEFAULT grammar would not only bloat the grammar rules but also 
increase the chance that new expression grammars introduced in future, 
which could conveniently interoperate with `default`, would be 
unintentionally excluded by omission.

Cheers,
Bilge

--------------2wPv3bob9k9LCHdNUo0CemYZ
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 7bit

<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <div class="moz-cite-prefix">On 25/08/2024 14:35, Larry Garfield
      wrote:<span style="white-space: pre-wrap">
</span></div>
    <blockquote type="cite"
      cite="mid:0cfd3a28-3cb0-4478-85fb-cf086d8e5c66@app.fastmail.com"><span
      style="white-space: pre-wrap"></span><span
      style="white-space: pre-wrap">
</span>
      <pre class="moz-quote-pre" wrap="">The approach here seems reasonable overall.  The mental model I have from the RFC is "yoink the default value out of the function, drop it into this expression embedded in the function call, and let the chips fall where they may."  Is that about accurate?</pre>
    </blockquote>
    Yes, as it happens. That is the approach we took, because the
    alternative would have been changing how values are sent to
    functions, which would have required a lot more changes to the
    engine with no clear benefit. Internally it literally calls the
    reflection API, but a low-level call, that elides the class
    instantiation and unnecessary hoops of the public interface that
    would just slow it down.<span style="white-space: pre-wrap">
</span><span style="white-space: pre-wrap">
</span>
    <blockquote type="cite"
      cite="mid:0cfd3a28-3cb0-4478-85fb-cf086d8e5c66@app.fastmail.com">
      <pre class="moz-quote-pre" wrap="">My main holdup is the need.  I... can't recall ever having a situation where this is something I needed.  Some of the examples show valid use cases (eg, the "default plus this binary flag" example), but again, I've never actually run into that myself in practice.</pre>
    </blockquote>
    That's fine. Not everyone will have such a need, and of those that
    do, I'm willing to bet it will be rare or uncommon at best. But for
    those times it is needed, the frequency by which it is needed in no
    way diminishes its usefulness.<span style="white-space: pre-wrap"> I rarely use `goto` but that doesn't mean we shouldn't have the feature.
</span><span style="white-space: pre-wrap">
</span>
    <blockquote type="cite"
      cite="mid:0cfd3a28-3cb0-4478-85fb-cf086d8e5c66@app.fastmail.com">
      <pre class="moz-quote-pre" wrap="">My other concern is the list of supported expression types.  I understand how the implementation would naturally make all of those syntactically valid, but it seems many of them, if not most, are semantically nonsensical.  Eg, `default &gt; 1` would take a presumably numeric default value and output a boolean, which should really never be type compatible with the function being called.  (A param type of int|bool is a code smell at best, and a fatal waiting to happen at worst.)  In practice, I think a majority of those expressions would be logically nonsensical, so I wonder if it would be better to only allow a few reasonable ones and block the others, to keep people from thinking nonsensical code would do something useful.
</pre>
    </blockquote>
    <p>Since you're not the only one raising this, I will address it,
      but just to say there is no good reason, in my mind, to ever
      prohibit the expressiveness. To quote Rob</p>
    <p>&gt;I'm reasonably certain you can write nonsensical PHP without
      this feature. I don't think we should be the nanny of developers.</p>
    <p>I fully agree with that sentiment. It seems to be biting me that
      I went to the trouble of listing out every permutation of what <i>expression</i>
      means where perhaps this criticism would not have been levied at
      all had I chosen not to do so. Why does that matter? Because PHP
      already allows you to do many more ridiculous things, they're just
      not routinely presented to you so they're not part of your mind
      map. The end-user documentation will also not mention the nonsense
      cases, so the average developer will not think of them. You can
      write, `include(1 + 1);`, because `include()` accepts an
      expression. You will get: "Failed opening '2' for inclusion".
      Should we restrict that? No, because that's just how expressions
      work in any context where they're allowed. Special-casing the
      T_DEFAULT grammar would not only bloat the grammar rules but also
      increase the chance that new expression grammars introduced in
      future, which could conveniently interoperate with `default`,
      would be unintentionally excluded by omission.</p>
    <p>Cheers,<br>
      Bilge<br>
    </p>
  </body>
</html>

--------------2wPv3bob9k9LCHdNUo0CemYZ--