Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129623 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 6C30C1A00BC for ; Tue, 16 Dec 2025 17:55:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1765907760; bh=Rwd80DmC8ddyLV4I+nFmi/ce4l4RD47dG5J+5YCNYnI=; h=Date:From:To:In-Reply-To:References:Subject:From; b=S90+0YDXrio33jwq6K32zHFD+EM+hEjfk02REt3Uuqjo0oQIc0TvDiUkQ7V6jmtAS AKAeu8PgNgz0r2i0mUfYnZ6veuNhXtECeufFKLMZKN8vwe8HcQsksolJHK12Eo+eI3 lNGNrHTmbcJFu7XVoIv7+ITux9sjSlG9IvPYVRCOkfT4HWSB1J/JRXgHLn2k0lzqjK eLmw0lwZPZkHUe3r9scXgjqb3TmTdxW5nXsaWsPOU7Km3priMVDZxgGr0MrLgbDsaK 8bKlSYdwy0Io1zwZHb5ici2TcHCgTVfbdhNxiGgrf7Y5qbpG9bJiPfNmouctJXfpyH lhWmL6w9nkNqw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 277D7180339 for ; Tue, 16 Dec 2025 17:55:59 +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=-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_NONE autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from fhigh-b8-smtp.messagingengine.com (fhigh-b8-smtp.messagingengine.com [202.12.124.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 ; Tue, 16 Dec 2025 17:55:58 +0000 (UTC) Received: from phl-compute-04.internal (phl-compute-04.internal [10.202.2.44]) by mailfhigh.stl.internal (Postfix) with ESMTP id 89F2D7A007E for ; Tue, 16 Dec 2025 12:55:53 -0500 (EST) Received: from phl-imap-01 ([10.202.2.91]) by phl-compute-04.internal (MEProxy); Tue, 16 Dec 2025 12:55:53 -0500 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=fm1; t=1765907753; x=1765994153; bh=rbM9izMf8+iBT8VErJLBV XW8CEqc6X1ZTJdtWPSxggQ=; b=VK/8hEc1AqbiwyR9eTaEupV8b0hRtLzHipAbd L4NS3WIay/QVpX47zbhRxh8JrV/DfwfbOPBWkVAoNIrao8Ism/OTl560Nex7Zv/s kxNB+TgFJnjBqqF6dfx9k20jqThZfG65fi/bepZQu3Y+GKh9BB+t7iQvUZ8ADAZt YH32hduwpkX4XCnwAh0Z8oGS3D5vb5IOoAtdmgm+0j/X8DOtG6MFbct145Wt+OG4 Wd7NWYBW9MH0iaOpCYC360lTUr3xJKwM/zxl2ZFMeDP0CdNYLChTqHW4WgotvrsU YKUqq6WenSLCv4eP40i2yjpcqVYGIiGJ2RRil61kIAvpZ5NIQ== 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=fm1; t=1765907753; x=1765994153; bh=r bM9izMf8+iBT8VErJLBVXW8CEqc6X1ZTJdtWPSxggQ=; b=ialq+Tv7MPjxwMhxP r/Ew5ViM7TO6/hXyJRPjvOv45AXNBcoz0eX8yemkSLA9am+t/di7W/FmZX4zcZ+O SjpzxMepG8QzmFcllJfHpxnAy5w7aCaHrufr/Wdy44xEvV3v21C3nhcQsY3bS+S0 eSyr8QeOoFKa8mhQyB4NzlCeV89WRHFbRHAnQFo7OBHH8DXkpLgPNKOdWwGPwhhO zqeQ75/1sr6C6FRrv7CDwdBggnDFfMfrbGedTToU+7gzk4rrnNNQCfgFOUBZIJ46 F/mxYpnDDq32vMZbe/dS067ZVaQkqsvp2iwTa+4up3nhuOBx5FntnVSl7hFMtD3i Tv21g== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgdegtdeffecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjug hrpefoggffhffvkfgjfhfutgfgsehtjeertdertddtnecuhfhrohhmpedfnfgrrhhrhicu ifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomheqne cuggftrfgrthhtvghrnhepudegvdelgfeugeehfeejteffudevleethfefgeejffffleeg tddtveekgeekudfgnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilh hfrhhomheplhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhmpdhnsggprhgtphht thhopedupdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehinhhtvghrnhgrlhhsse hlihhsthhsrdhphhhprdhnvght X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 1652A18C004E; Tue, 16 Dec 2025 12:55:53 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 X-ThreadId: ALvh3TDXSVwZ Date: Tue, 16 Dec 2025 11:55:31 -0600 To: "php internals" Message-ID: <1d59c5df-b7e9-402e-bb91-667f9910ba8c@app.fastmail.com> In-Reply-To: References: <70A79513-5503-467E-BC6F-2B0494A3EBB9@benramsey.com> Subject: Re: [PHP-DEV] [RFC] Context Managers Content-Type: text/plain Content-Transfer-Encoding: 7bit From: larry@garfieldtech.com ("Larry Garfield") On Tue, Dec 16, 2025, at 10:49 AM, Deleu wrote: > I think the problem might be less about the true meaning of => and more > about the context that it applies to. You can see that in 3 cases of > the arrow it involves some sort of key/value pair (2 array scenarios > and 1 match/case). In the case of arrow function, like I said before, > arrow functions are kind of a standard that stand up on their own. And > even then, the "evaluates to" is only partially because in arrow > functions the evaluation does not take immediate effect, it is parsed > into a Closure that needs to be invoked. For instance: > > ``` > $array = [ > 'key' => throw new Exception('Stop'), > ]; > ``` > > Here, the arrow evaluates to an exception that is immediately thrown. > > ``` > match ($foo) { > 'a' => throw new Exception('Stop because of A'), > 'b' => throw new Exception('Stop because of B'), > }; > ``` > > Here, the evaluation is more loose and it only takes effect when there > is a match, but it does take effect. > > ``` > fn () => throw new Exception('Stop'); > ``` > > Here, the evaluation never takes effect if the Closure is not invoked. > > In these 3 cases, we can see each having its own evaluation rule: > immediate, immediate only for the match, and delayed. If I were to put > into words, I'd say: > > array keys: evaluates to > match: evaluate to the matched key > arrow function: parse the syntax, does not evaluate to. > > ``` > foreach ($arr as $k => $v) {} > ``` > > Here I don't see it only as a bit inconsistent because it's not really > evaluating anything anymore. It is assigning a value. And this is where > it blows up for me. The first 3 cases we can argue semantics and point > of views, but they are minor nuances. Still, they're all cases where > something on the right is being evaluated for a reason on the left. On > foreach, $v stands on its own. It's not affected / impacted / dicated / > evaluated towards the left at all. It's not a bit inconsistent, it's > completely different. And the syntax for using () is largely similar to > foreach, which is why it should use `as` and not `=>`. > > foreach ($iterator as $key => $value) > using ($contextManager as $context) > > We can see that the only place where arrow ("evaluates to" / =>) is > used inside an instruction is in foreach and the syntax is split away > from the array itself because the keyword `as` is separating `$k => $v` > from the $iterator. I can totally see an argument for: > > using (new ContextManager as $contextManager which evaluates to $context) > using (new ContextManager as $contextManager => $context) > > Here, the return of `enter` would be [$this, $context] and the syntax > falls into place with a symmetry from foreach. I wouldn't strongly push > for this syntax because the following also works Well, in the vast majority case there will be no need to access the CM within the `using` block. If there is, then it's likely that enterContext() will be returning just $this already. So the $contextManager variable is unnecessary noise 99% of the time. But if we take that out, which get right back to: using (new ContextManager => $context) I suppose grammatically this would make sense: using (new CM() yields $v) But that's a new keyword that is very close to an existing keyword that means something totally different, so probably not the best idea. > In any case, I don't have a vote and I really like the RFC in general. Yay! --Larry Garfield