Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129631 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 C0AB31A00BC for ; Tue, 16 Dec 2025 22:58:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1765925941; bh=rfXoZuCSv3HwjZPNBVg2+tDLFUfJtTpPVK8OnCSyqYw=; h=Date:Subject:To:References:From:In-Reply-To:From; b=Yki8A/rmuiL57ZbOCtNs4cOpJlwzaR/mj02cp6M2H6bxK90XN3KpOCagVNYE+b5tm pGuSbP6sNh+VJZ/MU/q382Il5OVOUhzcesbSWnB5Q2dcug+cV9UPXAmjKuLPEc8Ahi y1lJPvo3aNmH7UsBveq46DsSMzwZLW/WieP1umpupwksBbR2rt+AK2naY1uTj0fxoz OqZzIi27mSlntAlV4wRJlHi7+6uOp6V0I4Zpaznd7H7OdyENV+w7uHJtn7WbDn29jo JM5JZpQ6fsgASlZC1zrpwDNcsw0zdC5diF7Zq918ZlRmLOhvAWCsKlSV6Glq087J+L YLIAHXoPlX0Xw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 97B231806CD for ; Tue, 16 Dec 2025 22:59:00 +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 fhigh-a5-smtp.messagingengine.com (fhigh-a5-smtp.messagingengine.com [103.168.172.156]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 16 Dec 2025 22:58:50 +0000 (UTC) Received: from phl-compute-05.internal (phl-compute-05.internal [10.202.2.45]) by mailfhigh.phl.internal (Postfix) with ESMTP id 02B7914000A2 for ; Tue, 16 Dec 2025 17:58:45 -0500 (EST) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-05.internal (MEProxy); Tue, 16 Dec 2025 17:58:45 -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=1765925924; x=1766012324; bh=D7HVo6WLj4XRbH0lqM3lsWRDF53YLvXeAE4QyoNQu+I=; b= VV0rcb6eunnmVRXQjqkmT4COJXIGCt3Icu9L2UaEY6h8a6ixAIAUo/JQQ7sIHfFJ 4zHRnkXt7RdJ7lqqyrDRKzCgKiDy0qn5x0lbC9HXlyWsChJWt7yYHnr1p8nZi5Kh DeATLYZj10npMWvd4AkOJKmn3IezhZZ4foCKbVUhvv66zqyBW4R9z4E/HyMwZD4q 9Uw2WA/JiPBQP3E0fgVowrDRC5RhXt6+2IFAPOkaAoNLoLxGV5QEEccDwSRKHMYY 7NiqErsa6DvYDSE1hYPk8BVdSbdJjLveSF4cfvlwsCUNAK/RQtc/Hwe3oxgsctJe 3LQC0CcstxtpYszkRD87ew== 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=1765925924; x=1766012324; bh=D 7HVo6WLj4XRbH0lqM3lsWRDF53YLvXeAE4QyoNQu+I=; b=bSWYBOjfdBWhIgg/g PD7vC9ID+jahR1r95dKitQd9eDRp0s8jjTFrB1xUaMmx+ralBc8Kxlv/aqLq8mqN 2AZldGv83au7ZvKQcs+pOHmcnh59SaIzzygis6Qm4FoKQRm0p5dqJnIV1tytoI+9 kZvFPCVDkUZcJeNZN453P51PeXiFNKX2x1vCkjFYbG4lERBAM6nc0FrDXysNab8h /HU1F4XGz8YKVzDOHBBYizSXci0sIbtudpUtwirkCoXC9PHFKjp16tr4qV4BvDGJ 7omnzE0BGLPC0yCV/XXKvyJLQwV9Nw4VBYDdrLw2S4CffOfxAzJsPks7r+AC/sre 0MhNQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgdegtdelgecutefuodetggdotefrod 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 17:58:44 -0500 (EST) Message-ID: Date: Tue, 16 Dec 2025 22:58:44 +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> <480eff88ceba74d3274917d6ce2a3c24@bastelstu.be> Content-Language: en-GB In-Reply-To: <480eff88ceba74d3274917d6ce2a3c24@bastelstu.be> 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 09:07, Tim Düsterhus wrote: > That definition doesn't make sense to me. An iterator that only ever > emits a single value is not actually iterating anything and it would > never occur me to interpret it like that. Well, firstly, it is certainly possible to have an iterator that only emits one item; or even no items at all. There are even design patterns that rely on that - in some languages, the Option/Maybe type is a zero-or-one-item iterator, and you unwrap the value using "map" to either call or not call a function. But that wasn't really the image I was trying to conjure; it's more about the relationship between the Iterator and the item. Here's a metaphor which might or might not work: You are at an arcade. There is a machine with a single button, and a tray. Every time you press the button, a toy drops into the tray. After you press the button a few times, toys stopping coming out, because there are none left in the machine. This machine is labelled "Iterator". Next to it, there is another machine which looks similar. When you press the button on this one, some music starts, and then a toy drops into the tray. When you press the button again, the music stops. No more toys drop. The toys are not making the music, and the music is not making the toys; they just both happen when you press the button. This machine is labelled "Context Manager". Then there's a third machine, which doesn't have the tray, only the button. You press the button once, and the music starts; you press it again, and it stops. This machine is also labelled "Context Manager". That's what I mean by "like an iterator with one item": that Iterators and Context Managers are similar kind of machines. The "foreach" and "using" statements don't create or move those machines, they *operate* them, pressing the button so the music plays and the next toy comes out. -- Rowan Tommins [IMSoP]