Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125231 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 128B31A00BD for ; Sun, 25 Aug 2024 18:46:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1724611730; bh=5VgveNGDaUcGAqYJGRuR98flNRbEjf1ImyupjKe1CqU=; h=Date:Subject:To:References:From:In-Reply-To:From; b=RselN3E5bwdn+N8B59/kGTWFVCwhKw+OY+KxwGDS3q7DvmY//NxCEUzAqc/fj5f+H W+HlJQ0eiBc5HlYFwDuC4DhCTQ3i85HXsa5h3D+q9OyEWyb4acEpxzcUo9VeT5ItlE ORnxDqsCj9/KO4cH/r2jixPOBTqPNFkZdpbDO5k+bYMiiXMOZYXcKZ4v6pxE3HO3fx ZLjfYLni/0YkEjiXZ6k8FIpdB+53yV7moE2tHoNRbFJD3q2esDxNeNPY0nYaYNUdLn fKS5oVbQpof8Vx08quvrM4N9n1LppZt+RdMFx3Hrqc18jypqP+HT7n682aLbfNvisp nWuDVfSukZTCg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E462818006D for ; Sun, 25 Aug 2024 18:48:48 +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,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS, SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from fhigh6-smtp.messagingengine.com (fhigh6-smtp.messagingengine.com [103.168.172.157]) (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 18:48:48 +0000 (UTC) Received: from phl-compute-07.internal (phl-compute-07.nyi.internal [10.202.2.47]) by mailfhigh.nyi.internal (Postfix) with ESMTP id E7DAD114EADE for ; Sun, 25 Aug 2024 14:46:55 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-07.internal (MEProxy); Sun, 25 Aug 2024 14:46:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rwec.co.uk; 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=fm1; t=1724611615; x=1724698015; bh=kQqQseVBT4 KSUeiDnrb24aFri5bvkT0DHdHTAe9q5vw=; b=qxTFIeLocOX+jkk1YU0dMO/HLt tIrIrHdig5XA3j+zZEiCyt//GSv+RcA9XBThYNhKr0HE5FjFPZIpMB72Itm+NiEL 8/2t2o6VkDQtEJYpiHzoBKDrXX3a/7beD+ipigVpSxty/hRQEuqPv9aX7Mk2myk9 dU3bG4KyNa9QtVuXEeId8NFoDmvC4XPASMms+B+Y4mIacZKvwML0uSvp1uOTSGWw 7iwsyxGKj4npFoWG2boIOT/q7c/Krn8XL8yXdOSHbQSGm/EywbTLKNRKnF/jtMa8 Umtdwm6cSRi4Xyd9/wYAB+wxLeC7JZG+xDq1dX8a8Up/cVNlj84pcX7MWcAw== 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=1724611615; x=1724698015; bh=kQqQseVBT4KSUeiDnrb24aFri5bv kT0DHdHTAe9q5vw=; b=jmQpmeGXmUb7ObFJxwOe3J+fcG5YcyziJK7Us17q5ILe KIM+0zAkNynzPnUYl/0yzsDvGSNP5rQsImSBIff5Xeu6Q4Ho8M/jwUd/9J9NPHFS EqOBLiJUJ6Jm0XnxDjc3hyb6PEG79l5qT4eeDbCUZ4eC92jxg0fRnc/8bD16q+/o To/453WHJ8hieKyDM+xbABXF9oMgx1LbxY/ttYbaGN36N4pYuSq6B0o0oHuFUl7h Lzzajp3ubO7OUdt3nZ5cibytcVEejPUOTqNDGRyfPxsAHfDKqYwEBiB1d2sMuLzV +2gZJ4GD2ZatmvwQne1ViEh+rJDrtX9nR0lFTky95g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddviedguddvjecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecuogfuuhhsphgvtghtff homhgrihhnucdlgeelmdenucfjughrpegtkfffgggfuffvfhfhjgesrgdtreertddvjeen ucfhrhhomhepfdftohifrghnucfvohhmmhhinhhsucglkffoufhorfgnfdcuoehimhhsoh hprdhphhhpsehrfigvtgdrtghordhukheqnecuggftrfgrthhtvghrnhepfeettdekhfdu keeufeevgeduveejieeigfdtffejheduteekveehjeekieeuffegnecuffhomhgrihhnpe efvheglhdrohhrghenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhl fhhrohhmpehimhhsohhprdhphhhpsehrfigvtgdrtghordhukhdpnhgspghrtghpthhtoh epuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepihhnthgvrhhnrghlsheslhhi shhtshdrphhhphdrnhgvth X-ME-Proxy: Feedback-ID: id5114917:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Sun, 25 Aug 2024 14:46:55 -0400 (EDT) Content-Type: multipart/alternative; boundary="------------tbrs04IaKwpCG6KNhq0bi3ZW" Message-ID: Date: Sun, 25 Aug 2024 19:46:54 +0100 Precedence: bulk list-help: list-post: 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: From: imsop.php@rwec.co.uk ("Rowan Tommins [IMSoP]") This is a multi-part message in MIME format. --------------tbrs04IaKwpCG6KNhq0bi3ZW Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 25/08/2024 18:44, John Bafford wrote: > 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. There's an easy argument against this interpretation: child classes can freely change the default value for a parameter, as long as they do not make it mandatory. https://3v4l.org/SEsRm That matches my intuition: that the public API, as a contract, states that the parameter is optional; the specification of what happens when it is not provided is an implementation detail. For comparison, consider constructor property promotion; the caller shouldn't know or care whether a class is defined as: public function __construct(private int $bar) {} or: private int $my_bar; public function __construct(int $bar) { $this->my_bar = $bar; } The syntax sits in the function signature because it's convenient, not because it's part of the API. > 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. This seems contradictory to me. If you use the default, you're telling the library that you don't care about that parameter, and trust it to provide a default. If you want to know what the library did with its arguments, reflecting the signature will never be enough anyway. For example, it's quite common to write code like this: function foo(?SomethingInterface $blah = null) {     if ( $blah === null ) {         $blah = self::_setup_default_blah();     }     // ... } A caller can't tell by looking at the signature that a new version of the library has changed what _setup_default_blah() returns. If the library doesn't provide an API to get $blah out later, then it's a private detail that the caller has no business inspecting. Regards, -- Rowan Tommins [IMSoP] --------------tbrs04IaKwpCG6KNhq0bi3ZW Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit
On 25/08/2024 18:44, John Bafford wrote:

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.


There's an easy argument against this interpretation: child classes can freely change the default value for a parameter, as long as they do not make it mandatory. https://3v4l.org/SEsRm

That matches my intuition: that the public API, as a contract, states that the parameter is optional; the specification of what happens when it is not provided is an implementation detail.

For comparison, consider constructor property promotion; the caller shouldn't know or care whether a class is defined as:

public function __construct(private int $bar) {}

or:

private int $my_bar;
public function __construct(int $bar) { $this->my_bar = $bar; }

The syntax sits in the function signature because it's convenient, not because it's part of the API.


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.


This seems contradictory to me. If you use the default, you're telling the library that you don't care about that parameter, and trust it to provide a default.

If you want to know what the library did with its arguments, reflecting the signature will never be enough anyway. For example, it's quite common to write code like this:

function foo(?SomethingInterface $blah = null) {
    if ( $blah === null ) {
        $blah = self::_setup_default_blah();
    }
    // ...
}

A caller can't tell by looking at the signature that a new version of the library has changed what _setup_default_blah() returns. If the library doesn't provide an API to get $blah out later, then it's a private detail that the caller has no business inspecting.


Regards,

-- 
Rowan Tommins
[IMSoP]
--------------tbrs04IaKwpCG6KNhq0bi3ZW--