Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125254 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 CB7E81A00BD for ; Mon, 26 Aug 2024 07:28:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1724657429; bh=YhaHBCvs3IIrkWBKVF1cDeDYKl6e9vsnI1CFqdOi3y8=; h=Date:From:To:Subject:In-Reply-To:References:From; b=mAy00X+oeBTRZUIrAIbu3600zRb816vIohlUbtMU8KX45l0jlPev0r4ZRY707feJC P89JaRHquz4LdAEgRYQN2Y/yukoZRH5NTleDKueW6QuFO+196eDCIkqLeNMUVR3nw2 RYT0sP5efL0mlvbFuaIHox3zLlZpmV01+P8u85ORKlzpVJbRhTTeZzjl507fhcpvq4 Q9/Nkixg3vQ+OxNFHMJJlBpdJ5uYcythoW3fdWOuN8b/ulATul/PDXFZSW5kLXBqF9 ZTHeia+Esyo/I41PzIALB7BlZ7ZvJfLc2IKpobH6Kuvip28vF05vBbspyf9LsAvUjv RIsAdEUKY4d1Q== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 16AD0180059 for ; Mon, 26 Aug 2024 07:30:28 +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,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 fout3-smtp.messagingengine.com (fout3-smtp.messagingengine.com [103.168.172.146]) (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 ; Mon, 26 Aug 2024 07:30:27 +0000 (UTC) Received: from phl-compute-05.internal (phl-compute-05.nyi.internal [10.202.2.45]) by mailfout.nyi.internal (Postfix) with ESMTP id 6140F138FC12 for ; Mon, 26 Aug 2024 03:28:34 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-05.internal (MEProxy); Mon, 26 Aug 2024 03:28:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rwec.co.uk; h=cc :content-transfer-encoding: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=1724657314; x=1724743714; bh=PUG3kzMeowXYu/1YwwJA1f9Vgw45ffTAZeqHfFhTT1Q=; b= kPvYi9U94wKL4yO0ksYuDYyUm8wX2g9t4sJL9CLhP4XSSeQbLKurBPDmLPgLlSgL rKltTlGMLmazwvfu3oB5Af8z4fTCUD1pW08EScGJNqR++ZFoz4r5qaox+GPHWWcT xQDVP19GblDKKuRTWaktyClZF5PuKwePTYVcfxcZ5rM4zpRBzss4BWtWrwa0x3Kl XRpX3gQrmJMpkdbInugUUkqqS9xkl3EkYoXmamgDSh1jyqLQZzIj3MDYRVUjO/NN 88RIIuOcHCGaXar3LxzaEgbUmri3/V6k6IRzV4HRBMpHfE0/yvAQw/6w0EEzqAU4 EpIEjz9AjBK+sHdywXwPEA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding: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=1724657314; x= 1724743714; bh=PUG3kzMeowXYu/1YwwJA1f9Vgw45ffTAZeqHfFhTT1Q=; b=J O0eGLsSJ0jRvGpQfNGrQIHBCDpb67UPzigrnufVciNEdvBK4IxFCnROVj0JVuWeR EIe2MNWrqMRtKMOuIFnHGqPsuyEvb2nCxSISVJvwKOwuqS8SgMjjJUrNj5cSsj16 biobQhNSEZWfOKK2FgYHPJ1cHxeg6FkfKJs/vOxWyBSMNjmUF0ibEDxr9MsokwHg ME1+QdQh+RIQMZcBKfqeF7uYmsFH43mNl7C2uoOI9SmLSItS2yF5/2TTf+atjk6l 872mJaleDT4p+9e515kAtJAXP9CRLCk6CW9f+CPyYE8/newI1hNhl/hYOnkkaJGm 1q+dhMjoE7Z7GuWEH+QSA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddvjedguddvtdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecunecujfgurhepfffhvf fufggjfhfkgggtgfesthhqmhdttderjeenucfhrhhomhepfdftohifrghnucfvohhmmhhi nhhsucglkffoufhorfgnfdcuoehimhhsohhprdhphhhpsehrfigvtgdrtghordhukheqne cuggftrfgrthhtvghrnhepheelffetiefgveduteefudegtdduveeludegueegleehiefh hefgtdekveevgfelnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilh hfrhhomhepihhmshhophdrphhhphesrhifvggtrdgtohdruhhkpdhnsggprhgtphhtthho pedupdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehinhhtvghrnhgrlhhssehlih hsthhsrdhphhhprdhnvght X-ME-Proxy: Feedback-ID: id5114917:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Mon, 26 Aug 2024 03:28:33 -0400 (EDT) Date: Mon, 26 Aug 2024 08:28:33 +0100 To: internals@lists.php.net Subject: Re: [PHP-DEV] [RFC] Default expression User-Agent: K-9 Mail for Android In-Reply-To: <99846F78-38F8-4549-B0A6-6310933AA78D@newclarity.net> References: <792a811e-edf8-4a82-8422-e11cc302a6db@scriptfusion.com> <71F1A1D0-9958-4C86-B8C4-50B502B7560D@getmailspring.com> <99846F78-38F8-4549-B0A6-6310933AA78D@newclarity.net> Message-ID: <88BCC47D-C8FF-44DB-8816-17CB899CD887@rwec.co.uk> Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: imsop.php@rwec.co.uk ("Rowan Tommins [IMSoP]") On 26 August 2024 05:44:44 BST, Mike Schinkel wrot= e: >> On Aug 25, 2024, at 12:21 PM, Rowan Tommins [IMSoP] wrote: >> The Reflection API is a bit like the Advanced Settings panel in a piece= of software, it comes with a big "Proceed with Caution" warning=2E You onl= y move something from that Advanced Settings panel to the main UI when it's= going to be commonly used, and generally safe to use=2E I don't think allo= wing arbitrary operations on a value that's declared as the default of some= other function passes that test=2E > >You analogy is faulty=2E You are conflating a complex API =E2=80=94 Refle= ction =E2=80=94 with one use-case of that API which =E2=80=94 per the RFC = =E2=80=94 has well-defined syntax and semantics and purely due to its simpl= icity is more likely to be used than the Reflection API and far less likely= to be used incorrectly than the Reflection API=2E You are misunderstanding the analogy=2E The analogy is that the Reflection= API as a whole is like the Advanced Settings page, with its big "Proceed w= ith Caution" sign=2E Accessing the default value of someone else's function= is like a setting which you can only currently access on that advanced set= ting screen, but people are proposing we move to a big tempting tickbox on = the main UI=2E I was responding to someone justifying anything and everything the proposa= l allows, because Reflection already allows it=2E If the feature was "first= class syntax to access private methods of a class", I don't think it would= be controversial to challenge it=2E Saying "Reflection can already do it" = would be a poor defence, because part of Reflection's job is to break the n= ormal rules of the language=2E >> On Aug 25, 2024, at 11:31 AM, Rowan Tommins [IMSoP] wrote: >Can you give a specific example from code we are likely to find in a prod= uction application =E2=80=94 vs=2E a forum debate =E2=80=94 where someone i= s likely to use `default+1` AND where it would be problematic for the autho= r? The overriding rule, in my head, is that the caller shouldn't need to know= , and shouldn't be able to find out, what a particular implementation has c= hosen as the default=2E So the particularly problematic operations are thin= gs like this:=20 foo($whatWasTheDefault=3Ddefault)=20 foo(logAndReturn(default)) foo(doSomethingUnrelated(default) && false?: default)=20 I can see people inventing use cases for these as soon as they're availabl= e, but by doing so they will be completely changing the meaning of default = parameters, which currently mean "I trust the implementation to substitute = something valid here, and have no interest in what it is"=2E Note that under inheritance, the default value may even change type: class A { public function foo(int $bar=3D42) { =2E=2E=2E } } class B extends A { public function foo(int|string $bar=3D'hello') { =2E= =2E=2E } } Perhaps that would be more obvious if the declaration happened to look lik= e this:=20 function foo(optional int $bar) { default for $bar is 42; // =2E=2E=2E } As far as I can see, nobody has actually justified reading values out in t= his way, only said it's a side-effect of the current implementation=2E You ask how a library can provide access to that default, and the answer i= s generally pretty trivial: define a public constant, and refer to it in th= e parameter definition=2E I sometimes do that with private constants anyway= , just to make the value more easily documented, or use it in a couple of d= ifferent contexts=2E The only exception I think is "new in initializer", where you would have t= o provide a function/method instead of a constant, and couldn't currently r= euse it in the actual signature=2E Aside: one of those examples brings up an interesting question: is the val= ue pulled out by "default" calculated only once, or each time it's mentione= d? In other words, would this create 3 pointers to the same object, or 3 di= fferent objects?=20 foo(array|Something $x=3Dnew Something); foo([default, default, default]); Rowan Tommins [IMSoP]