Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127436 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 lists.php.net (Postfix) with ESMTPS id 0AA821A00BC for ; Fri, 23 May 2025 14:55:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1748012013; bh=EozIcD60wDqAd3LfzYdPy33jpNMOwHoX10z4PmcYrZk=; h=Date:From:To:In-Reply-To:References:Subject:From; b=hyHJ/5mDDCV9A+E37n2OvTPdUcx7rllnR3Cvo7/D3VXDlG1Uy8Mz0FMXElyR4AoP5 tnS57wKOH7RcpYbv8mycpzg3jb1Z5b1iMjjhSOrLEP5phTwRS7YArbCBpR3JA1nu5j nYwDGBgGMJ+L5chU+HYd/uA+/pxGMdtd2x9774hx66df6t95SlBt4QqOkvcKs3mmaj dF7euGXiLNx7vu8HwgznyUX89ctj+YMvpeIOBvovJJQ3VO1d0nA8D1HjiGcR8aSAgE U3QLA9wNl3E6zckJEBvXlQ7ZcBlJg7pdyiFcma/3CB3zNcrVUENps2aI6KgwNamChJ 03+ZkUuzJAM6A== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 3FF39180083 for ; Fri, 23 May 2025 14:53:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_05,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from fhigh-a8-smtp.messagingengine.com (fhigh-a8-smtp.messagingengine.com [103.168.172.159]) (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 ; Fri, 23 May 2025 14:53:31 +0000 (UTC) Received: from phl-compute-10.internal (phl-compute-10.phl.internal [10.202.2.50]) by mailfhigh.phl.internal (Postfix) with ESMTP id 39F6C1140110 for ; Fri, 23 May 2025 10:55:39 -0400 (EDT) Received: from phl-imap-02 ([10.202.2.81]) by phl-compute-10.internal (MEProxy); Fri, 23 May 2025 10:55:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; 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=fm3; t=1748012139; x=1748098539; bh=+w5KsGfGEr6OvaREgrszm UwymCo/uy3UlJAXmaxsxCk=; b=Pkf4mZI8irPZtN7e3hRFUpeDhpqdF6yIy++pR SD8m0D/OE/yS9cUIIkdQ39OTyCLlUfSFEJdU3MKE2aiDmVOXyFbC7FeR/KLZBICW +0Wr0GhDihcQV9goxbZVR2IvCiVThJ/9o7ud7VwNtXxIckvcIel7mC/5iQqwyt3r ZIyZN5VhpD064+wI1fdmWHj/hL6GhBsOJBLAcPwVYkZQSvk+g78dx4PdBOrZP9af MXgQjlGLbkTRv8seimThR/FMKfCNVZOVnaHHKmSlqY9Jcs3lKkRvo2oLaIXGaD5L IQhvZAo9WLyNXg9B94KZiWVoTe1lB6BSqxaZ4AfQFmXaEBGTQ== 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-sender :x-me-sender:x-sasl-enc; s=fm3; t=1748012139; x=1748098539; bh=+ w5KsGfGEr6OvaREgrszmUwymCo/uy3UlJAXmaxsxCk=; b=t0A3oMK5bQR4HeRSX spGAyM7dTKMfuqEM2nW6sbd0JqWb2bugKr6QTfa1cOanRrWbBXpI1xvIohbIpbzB WqIvm5xi0bgj2LzedyOgZY000QLj/4q+D0157mX/Lm+yKRsMDLp3i0WvzHdm7lV1 w6zaJ2xPkm7Q7Fy9b17IV7jsKssnIXYdrqEcgZZ9qyM2o09BXjBcqTymGa203C6q Fp9o2sfQju1a6johXenZ8qcMz/C8Uzk3DDhl/zDptISNZs/EnM+0GIZ3oQMAfa8S DmOLFnnenf9h9RxRQkpN6PIwj28lbrO/JKed9gF3+kjKQGP1RcseIeJw7c3gpMd2 0UkGA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtddtgdeludehucdltddurdegfedvrddttd dmucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgf nhhsuhgsshgtrhhisggvpdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttd enucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhepofggfffhvffkjghf ufgtgfesthejredtredttdenucfhrhhomhepfdfnrghrrhihucfirghrfhhivghlugdfuc eolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhmqeenucggtffrrghtthgvrhhn pedugedvlefgueegheefjeetffduveeltefhfeegjeffffelgedttdevkeegkedugfenuc evlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehlrghrrhih sehgrghrfhhivghlughtvggthhdrtghomhdpnhgspghrtghpthhtohepuddpmhhouggvpe hsmhhtphhouhhtpdhrtghpthhtohepihhnthgvrhhnrghlsheslhhishhtshdrphhhphdr nhgvth X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id D8698700061; Fri, 23 May 2025 10:55:38 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 X-ThreadId: T8b89c4a623bdae75 Date: Fri, 23 May 2025 09:55:14 -0500 To: "php internals" Message-ID: In-Reply-To: References: Subject: Re: [PHP-DEV] RFC: Single-Expression functions Content-Type: text/plain Content-Transfer-Encoding: 7bit From: larry@garfieldtech.com ("Larry Garfield") On Thu, May 22, 2025, at 8:53 PM, Anton Smirnov wrote: > Hi Dmitriy > > On 22/05/2025 12:24, Dmitry Derepko wrote: > > I'm aware that Larry Garfield previously proposed a similar feature > > several years ago, though it unfortunately didn't pass the voting stage. > > I would like to respectfully suggest that using "=" instead of "=>" to > > separate declaration and implementation might be a better approach. > That looks like the weakest part of the proposition because we already > have two places where inline bodies are used: the mentioned arrow > functions and property hooks > > public string $foo { get => 'dynamic value'; } > > No sense in introducing a new syntax for basically just another case of > inline function body. > > > // oneline > > function handle(string $input): string = func1($input) |> func2(...) > |> func3(...) |> func4(...); > > That looks like a callable assignment like you know > > $f = fn ($bar) => $this->bar + $bar; > > class Foo { > private $bar; > > public function bar() = $f; > } > > that may confuse users, another argument for => > > -- > Anton Like Anton, I believe the arguments for using => and not = are strong, as detailed in the original RFC. Other than that, I am unsurprisingly in favor of short-function syntax. If memory serves, the main argument against last time was "it doesn't actually do anything." It's purely sugar. Which is true, but IMO also not a fully compelling argument. Constructor promotion is purely sugar, but it absolutely makes life better. The short-hooks syntax is purely sugar, but makes life better. The question is whether the QoL improvement of the sugar justifies the engine complexity + conceptual complexity (for readers) that every feature comes with. In this case, the engine complexity is not zero, but pretty close to it. The conceptual complexity is also low, especially if using =>. It is already established to mean "evaluates to", which is exactly what is described here. So the overall cost of this change would be quite low. While the QoL benefit is not as large as it was for constructor promotion (which was huge), I do believe it is large enough to justify the fairly low cost. Especially as we integrate more and more expression-oriented features over time (pipes, null-safe methods, match(), throwable expressions, etc), which increases the surface area where the benefits will be felt. --Larry Garfield