Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129626 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 5FEC61A00BC for ; Tue, 16 Dec 2025 20:47:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1765918055; bh=7NJ2whPUfvoKODamJqgFb32plkiZxwclYqkFneYenXg=; h=Date:Subject:To:References:From:In-Reply-To:From; b=ARyTF0rXYKQ9t5c7gn++C9/zH2L9M4TddbXlSA0N1OeR+R4UpKnUDoHXezNK7tYui iFz7AQNiXZXmp4K4BO6yRLM/jxVpxyIFh21T/i+TWmlIePC/NoGonMxzaxpGL7ve2j Xl8PQC+S8e0bNTp7A47ixrklB3EEJHrZKWYtRqxHeRxS/dsKdZEXMVUyEcoetRJWWf 11ceuU/jDvuwaXI0dDiiiTHeGQxfhq1F4QxJ/hY+3qzICQaRuK9TzRdiUvS2c3Pe3H BO+AS5q1oY7MKdVI7CrKw1DuV/C/05R5J6z5WYv8oHdiRExuip6Gc4xObILSIXYGTl PkMXTRjg1Qv+A== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E81771801D5 for ; Tue, 16 Dec 2025 20:47:34 +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_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from fout-a2-smtp.messagingengine.com (fout-a2-smtp.messagingengine.com [103.168.172.145]) (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 20:47:34 +0000 (UTC) Received: from phl-compute-04.internal (phl-compute-04.internal [10.202.2.44]) by mailfout.phl.internal (Postfix) with ESMTP id 0F2CBEC0095 for ; Tue, 16 Dec 2025 15:47:29 -0500 (EST) Received: from phl-frontend-01 ([10.202.2.160]) by phl-compute-04.internal (MEProxy); Tue, 16 Dec 2025 15:47:29 -0500 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=1765918049; x=1766004449; bh=K4MncNIqNS/7ikHx0cORlJT5Y5xqjtB44g36ogFi09A=; b= Us3sYiOOj8y8xVagF8dWhZsqKKQDGeS/05/+BaslDqLLcbazntzoGSUmzmpz94Rx 89bmuCy94aDHYYZ2QLEOK0ikVWL6+sssRxS5oJf8AFUfnYk9Le0byiBSmCehus8R w+zGtTFv9ezvTRC+ucHRpINga2II4gd+nLE2g/o0gXlqwmU8XsOP2FrtNefrKK6X 1dE3ScWVuzJtuF7/dLzTywhvMAffsrC992cxlydc1/9graSGCBkXARZyyMoB62Zi 07khkQ7iDVo4Ty3VzyDaTOL0EpiLeAz5x+qkMVkpH5cn4hUvXRPF6+8TLq5uI5Da KTfPQMGlujl9Hje+ZgwzFg== 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=1765918049; x=1766004449; bh=K 4MncNIqNS/7ikHx0cORlJT5Y5xqjtB44g36ogFi09A=; b=iD/aHRan2HRVEQ0Ry v3x3mqQEjyi3cPMhUnrFotikme9rhMROOtFduyUC/raJOQrhR/tgtyYR2i1sTwMq e4AVGyQnjGFjsbBibEAy+R2C2N2TnCZ+u2hZq8yW3pLxxsHjnas1FAhjOr1Fd4BV 4QyNdOJdWKVQLUGq9jqvubUKqiZPURynoFVka+pMzaTr4CeBCJHSuUv69FqWOJHC CRzFZgZoaqZUjC5leIG8B86B4VKaYlRLoEEUS0KNzmfZtzo5a9V+NhG8lbPppUvv zUr5gtUbJkj9FQ768alGcdhf4Vp5ipTw13jbwifMNJLD3eeqls0/KsMj+mkTAx8v PwjuA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgdegtdeikecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecunecujfgurhepkfffgggfuffvfhfhjggtgfesthekredttd dvjeenucfhrhhomhepfdftohifrghnucfvohhmmhhinhhsucglkffoufhorfgnfdcuoehi mhhsohhprdhphhhpsehrfigvtgdrtghordhukheqnecuggftrfgrthhtvghrnhepffekve duffduvdehjedvfeekleeftddugeefheejudehgeeiudffgeeggeevfeehnecuvehluhhs thgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepihhmshhophdrphhhph esrhifvggtrdgtohdruhhkpdhnsggprhgtphhtthhopedupdhmohguvgepshhmthhpohhu thdprhgtphhtthhopehinhhtvghrnhgrlhhssehlihhsthhsrdhphhhprdhnvght X-ME-Proxy: Feedback-ID: id5114917:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 16 Dec 2025 15:47:28 -0500 (EST) Message-ID: <24592968-1702-4607-bafe-c6cfa437e818@rwec.co.uk> Date: Tue, 16 Dec 2025 20:47:26 +0000 Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PHP-DEV] [RFC] Context Managers To: internals@lists.php.net References: <70A79513-5503-467E-BC6F-2B0494A3EBB9@benramsey.com> Content-Language: en-GB In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit From: imsop.php@rwec.co.uk ("Rowan Tommins [IMSoP]") On 16/12/2025 11:25, Deleu wrote: > My conclusion here is exactly the opposite of yours because this > explanation makes `as` even more symmetrical now. I haven't exactly reached the "opposite" conclusion. If anything, I've now reached the conclusion that "as" and "=>" are both equally ambiguous and easy to misinterpret. > As you've mentioned `foreach(new MyIterator as $iterator)` is not how > it works. An iterator *produces a value* that is assigned to the > variable after `as`. Symmetrically, `using(new ContextManager as > $context)` the ContextManager is also producing a value that is > assigned to the variable after `as`. The only difference is in the > keyword: foreach will loop, but using will not loop since > ContextManager is not an iterator. That is certainly how I read it, having already been primed by mentions of iterators in the Python design document. However, Tim pointed out (as you say, it came up in a different thread) that the "each" is doing important work in the phrasing "for each ... as". (It occurs to me that PHP used to have an actual function called each(), which gave you an item from an array.) Without that hint, the "X as Y" could easily be misread as meaning that X and Y are the same thing. In plain English, "using the screwdriver as a hammer" means the screwdriver and the hammer are the same object. In PHP, "use Foo as Bar;" means Foo and Bar refer to the same class. On 16/12/2025 15:59, Larry Garfield wrote: > Second, I find it fascinating that there's so many different mutually-incompatible spins on what => means. I think we're all engaging in a lot of post hoc rationalisation for a bunch of syntax that's evolved haphazardly, with multiple inspirations. I was particularly amused by this: > For the arrow function, it's kind of implied in the name ARROW > function that we would need a syntax in the lines of `fn () =>`. It makes me imagine a Computer Science researcher named Dr. Arrow, who invented a new kind of function, but didn't know how to write it until their friend pointed out that their name would make a suitable pun. In reality, I suspect there are at least two lines of origin: 1) The key => value syntax for arrays is pretty clearly inspired by Perl, which was far and away the most popular web programming language in the early 1990s. In Perl, it's called the "fat comma", and (a => 'b') is actually a synonym for ('a', 'b'). 2) Using some form of "args arrow expression" for lambda functions comes ultimately, I suspect, from Functional Programming languages. The "=>" in match statements can probably be traced to there as well. Notably, exactly what arrow is used varies from language to language. CoffeeScript (created in 2009) has both "(args) -> expression" and "(args) => expression" with different semantics; JavaScript/ECMAScript basically adopted the "=>" version in 2015. Meanwhile, C# added "(args) => expression" in 2007; Java added "(args) -> expression" in 2014. Hack used "(args) ==> expression" but needed an ugly parser implementation, and an early PHP proposal for "(args) ~> expression" was rejected, so we ended up with "fn(args) => expression" instead. Ultimately, the thing that all the uses of "=>" have in common is some reason to want an ASCII representation of an arrow, and the need to fit it into the constrained space of an existing grammar. The same is basically true of "as" - it's a nice short English word, with multiple meanings. That's a blessing and a curse: a blessing, because we can reuse it in different contexts without reserving more words; a curse, because people might have different intuitions about which meaning was intended. Which brings me back to where I started this e-mail: my conclusion is that neither "as" nor "=>" is clear and unambiguous. We could probably pick either, and people would get used to it; or we could try for something better. Regards, -- Rowan Tommins [IMSoP]