Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125228 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 C97C71A00BD for ; Sun, 25 Aug 2024 17:44:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1724607983; bh=OEazB/jPhpL+GOTgLxzC270Y9BvBjEA7jp4n3WoNgYE=; h=Subject:From:In-Reply-To:Date:Cc:References:To:From; b=MrMZDggeYqmcGgs2DnhWfVolyy4ERTIBEW68YC6b+wLoL/XbvKPlE1WUezPC9VRdI rfnTuYy8bqtg9wfstcPphsUklhYbB53Jycw9cgtD/UnyOrK70LILIMjXqXorthO1gu nG72V+pTVB7eYC+nAzi/spfddqypfIJITVCzejazBlF8X/8/Q9wg2KQ6HrebXaW8Iz 6ek3QOD4RuVCllsAhUcL0cls28JOhTljgVt/wNCf9wulK+e1Pw58qL72WAN9k1c7V0 qsFNq7U1MEOaXb7O7sOm8sjCsJyK9TxmooLkrPKr2ly92wvarC+YAcPVbOIOR3LdPW icYcy1i0PEmfg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 3CFB4180078 for ; Sun, 25 Aug 2024 17:46:23 +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.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from nebula.zort.net (nebula.zort.net [96.241.205.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sun, 25 Aug 2024 17:46:22 +0000 (UTC) Received: from smtpclient.apple (pulsar.zort.net [96.241.205.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by nebula.zort.net (Postfix) with ESMTPSA id C4FA4202F2C57; Sun, 25 Aug 2024 13:44:29 -0400 (EDT) DKIM-Filter: OpenDKIM Filter v2.11.0 nebula.zort.net C4FA4202F2C57 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zort.net; s=zort; t=1724607869; bh=3D25ha7pFWj/cgY4KbM+kjvqzrpo3Z02M4njy4ZcnAA=; h=Subject:From:In-Reply-To:Date:Cc:References:To:From; b=GH+/Z0aHF69GB/ja7e1Fd4ceucxWoLwSdELJopSeVbEgiP+doEyw94OG8+mQoiA5k lI6QCrygOYGJKPTG2ur1eNuXmowjFkBLqoq6R0EjBzOGj0qMc9vRUWYMeD78Kv2l0i O9U35l+KCp7sHNcFLtLzYAJFrNZdEfZXYNYEWrNQ= Content-Type: text/plain; charset=us-ascii Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3776.700.51\)) Subject: Re: [PHP-DEV] [RFC] Default expression In-Reply-To: Date: Sun, 25 Aug 2024 13:44:19 -0400 Cc: internals@lists.php.net Content-Transfer-Encoding: quoted-printable Message-ID: References: <0c8ed5d6-5507-4c41-8d7f-05d14ba8aa4c@scriptfusion.com> <0cfd3a28-3cb0-4478-85fb-cf086d8e5c66@app.fastmail.com> To: "Rowan Tommins [IMSoP]" X-Mailer: Apple Mail (2.3776.700.51) From: jbafford@zort.net (John Bafford) Hi Rowan, > On Aug 25, 2024, at 11:31, Rowan Tommins [IMSoP] = wrote: >=20 > 3) The expression should be passing additional information into the = function, not pulling information out of it. The syntax shouldn't be a = way to write obfuscated reflection, or invert data flow from callee to = caller. > - No assignments. > - No ternaries with "default" on the left-hand side - "$foo ? $bar : = default" is acting on local knowledge, but "default ? $foo : $bar" is = acting on information the caller shouldn't know > - Same for "?:" and "??" > - No "match" with "default" as the condition or branch, for the same = reason. "match($foo) { $bar =3D> default }" is fine, match(default) { = ... }" or "match($foo) { default =3D> ... }" are not. I think this brings up a good question on what exactly should be = intended to be public API. Currently, there's two main ways to = effectively write a default parameter: function foo(int $param =3D 42) {} function bar(?int $param) { $param ??=3D 42; } In the former, the default value is listed in the function declaration, = along with the function name, and parameter type and name, which are = already part of the public interface. In the latter, the default value is an implementation detail of the = function, and is not part of the function declaration. (You could also ?int $param =3D 42, but I'd argue that at that point, if = you really need to distinguish among the set of (unspecified, null, = value), you're better off with an ADT, which we don't have yet. And you = can also explicitly expose a default value as a static value on a type, = when a function itself doesn't want to/shouldn't make the policy = decision of what the default is.) Although I'm not sold on the idea of using default as part of an = expression, I would argue that a default function parameter value is = fair game to be read and manipulated by callers. If the default value = was intended to be private, it shouldn't be in the function declaration. One important case where reading the default value could be important is = in interoperability with different library versions. For example, a = library might change a default parameter value between versions. If = you're using the library, and want to support both versions, you might = both not want to set the value, and yet also care what the default value = is from the standpoint of knowing what to expect out of the function. -John=