Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125325 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 656F61A00BD for ; Tue, 27 Aug 2024 18:37:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1724783933; bh=5FMFytrF6yMFaTqBoX+YClNUcmJcBrt0+N6U5SSPaMQ=; h=Date:Subject:To:References:From:In-Reply-To:From; b=OfsoUZ6r0hai7Atj19ramQOx9XDmfv9D6/Os7u+2I6oeFgxOfCYlvDyVkNom9Gy25 8WV2iRt9haXweeqM8010hszcuSkNvLN/HkbODZ4TqsEexl5B7TxnevO7bnPvEmgGpQ VtJ+htJjM+VuWuwJ0jL6qlPXdBtiKL8X4rrsFoBM5TBNdGLjwriijfl3DQ3WMatYTR s7jW2SKNJ3MkMXUhZoaUv1T0WMjJPWmpIjuy7EfqsOQoAHHWDxrS6MPat/VlcBiBOh KFcOC+dkzetGpLNvBg+xg2GedNjLN6bcDFUT+oZnIayTAYIzBeVg67h7orekMMaGna z5YLaSVM2C2ZA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E3CAB18005B for ; Tue, 27 Aug 2024 18:38:51 +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 fout8-smtp.messagingengine.com (fout8-smtp.messagingengine.com [103.168.172.151]) (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 ; Tue, 27 Aug 2024 18:38:51 +0000 (UTC) Received: from phl-compute-06.internal (phl-compute-06.nyi.internal [10.202.2.46]) by mailfout.nyi.internal (Postfix) with ESMTP id 276A9138FF5E for ; Tue, 27 Aug 2024 14:36:57 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-06.internal (MEProxy); Tue, 27 Aug 2024 14:36:57 -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=1724783817; x=1724870217; bh=4HZavHDI0B m5p36eHHTwQbUMlshXwm/jfHClZtawrq8=; b=FDF7KZXt1/daTJaUpZ2f3zfB1v sRuW7B32dg4PdulMFg0xCe/wjqa1ICzr9sJP4lzo3TUdtKbXtAYEVbOOD9FDLZdA b5x9CAhBCKy312yuxlYEnBKHlXjLd3AEFplIHiGe07qAn1SEaWaTuoz2wP6paMIj SZemo585nqsZlxxZyU+w7UeWaMTs//kNm+hYZykdI5DD7a9WUiywkIYuIMQhpfWO cEr5h8S9qYG7cHFyxS4oXoVtJ8iB2qaYcL0d9VmE5JTHkqS/2hHSu6Q8gPfRne5S 5Api/rzLh1GaP2GcONhSHkngSG0zrEwW99mGuW3OCnkKwUMKuVl7XaXynxcQ== 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=1724783817; x=1724870217; bh=4HZavHDI0Bm5p36eHHTwQbUMlshX wm/jfHClZtawrq8=; b=OU6RWyk1W8KMYMVpQHJXeF/xenT+l+UZqrmVXo1/DAvU NDTeWDahl92BsRfAIR1rGrlrzHxHcShwNoi7l1iy9qxjc3CjhkuCnkvaiIbC2px8 KoMO5xEi1XTqUOcN2JlVNiqzpy9Ds+RaIgiUQUK9vlQT1mNp2Qn2rmBbHNO5w34S 0YwgnMjBz7/JPadpo6Ftjw6GJYMVe+xAgiGePsl0wn/ZROrSQgOmgFIdUiqRzcVQ h+YyG9/1DHz/UfrPqyW3KN8KtcRlc63j2ltSuklMUr+NsSmx2D7eu07lpAx1plh+ 8CrwZuNMyeMblvIGdenma8fPW0FvWs4r4DhkR3bA3Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudeftddguddviecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecunecujfgurheptgfkff ggfgfuvfhfhfgjsegrtderredtvdejnecuhfhrohhmpedftfhofigrnhcuvfhomhhmihhn shculgfkoffuohfrngdfuceoihhmshhophdrphhhphesrhifvggtrdgtohdruhhkqeenuc ggtffrrghtthgvrhhnpeehteelieeigfeuudeiueeiffdvveehudeufeekjeeugffffedt iedtgeettdelteenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfh hrohhmpehimhhsohhprdhphhhpsehrfigvtgdrtghordhukhdpnhgspghrtghpthhtohep uddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepihhnthgvrhhnrghlsheslhhish htshdrphhhphdrnhgvth X-ME-Proxy: Feedback-ID: id5114917:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 27 Aug 2024 14:36:56 -0400 (EDT) Content-Type: multipart/alternative; boundary="------------JhuqeHhRF11BZp50oaqc5JRZ" Message-ID: Date: Tue, 27 Aug 2024 19:36: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> 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. --------------JhuqeHhRF11BZp50oaqc5JRZ Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 27/08/2024 16:03, John Bafford wrote: > I'm not sure this could even work at all. The "default" parameter to > gettype() isn't the default value of the third parameter to > json_encode(). It's the default value of the first parameter to > gettype(). Which would probably fail, since gettype()'s first parameter > doesn't have a default. I suppose this could be solved by specifying an > offset or label (e.g. as with `continue 2` in a nested loop), but that > would just make it even harder to read. Ah, good catch. So without a pattern-matching "default is int", I'm not sure how you'd even achieve that safety. There are a few other examples on this thread that contain the same mistake, such as MWOP's: class A {     public function __construct(private LogInterface $logger = new DefaultLogger()) { } } class ProxiedLogger implements LogInterface { ... } $a = new A(new ProxyLogger(default)); The "default" wouldn't look anything up in A::__construct, only in ProxyLogger::__construct. To pass the default out to any kind of function, you'd have to write some contorted expression like this: $a = new A( $default=default && false ?: new ProxyLogger($default) ); That's even further into Obfuscated Code Contest territory than "default => default", and further reduces the reasonable use cases for expressions. -- Rowan Tommins [IMSoP] --------------JhuqeHhRF11BZp50oaqc5JRZ Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit
On 27/08/2024 16:03, John Bafford wrote:
I'm not sure this could even work at all. The "default" parameter to 
gettype() isn't the default value of the third parameter to 
json_encode(). It's the default value of the first parameter to 
gettype(). Which would probably fail, since gettype()'s first parameter 
doesn't have a default. I suppose this could be solved by specifying an 
offset or label (e.g. as with `continue 2` in a nested loop), but that 
would just make it even harder to read.


Ah, good catch. So without a pattern-matching "default is int", I'm not sure how you'd even achieve that safety.


There are a few other examples on this thread that contain the same mistake, such as MWOP's:

class A {
    public function __construct(private LogInterface $logger = new DefaultLogger()) { }
}

class ProxiedLogger implements LogInterface { ... }

$a = new A(new ProxyLogger(default));

The "default" wouldn't look anything up in A::__construct, only in ProxyLogger::__construct. To pass the default out to any kind of function, you'd have to write some contorted expression like this:

$a = new A( $default=default && false ?: new ProxyLogger($default) );

That's even further into Obfuscated Code Contest territory than "default => default", and further reduces the reasonable use cases for expressions.


-- 
Rowan Tommins
[IMSoP]
--------------JhuqeHhRF11BZp50oaqc5JRZ--