Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129114 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 6BDD31A00BC for ; Thu, 6 Nov 2025 12:19:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1762431582; bh=aBt71oio3snTZOB3si+wuttcrO3jcNusWMQRceDjC5o=; h=Date:From:To:Subject:In-Reply-To:References:From; b=T98fy8qscAjIS4OPYejLNWrGc+vW3g6ifB3Q8B2Pc/FOcg5lVqAPFZNDZAGS9Qyu6 MpH+yD3V1Ns4Z32CF7l4XsQ8swzx6Ky+L8X6ZU6B+9XB0LyvlGYpzAyLjTLg5DJpp6 zmEAvyL+w7j8OoFTI0sNx0Hci0ld3vKZwt4UNqLuLyIbzNuZTiA0VlJNkepkG+ULhG ldAislDMWRHkjtc5WOGZSwJRyUsesKO3d2Y/KmCqDKVHJgR1I80iPkVW+qW4QkRbIV vL8ViUdmGBbWBNBV89V1W8sYmVyjq8W5A3tZD0VU+ICX9MDiS/c4xm4yjjvOHcFhyV QtCNouGtFmeJg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 27C46180084 for ; Thu, 6 Nov 2025 12:19:41 +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=-2.8 required=5.0 tests=BAYES_00,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-b7-smtp.messagingengine.com (fout-b7-smtp.messagingengine.com [202.12.124.150]) (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 ; Thu, 6 Nov 2025 12:19:40 +0000 (UTC) Received: from phl-compute-04.internal (phl-compute-04.internal [10.202.2.44]) by mailfout.stl.internal (Postfix) with ESMTP id 2B1F91D000B0 for ; Thu, 6 Nov 2025 07:19:35 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-04.internal (MEProxy); Thu, 06 Nov 2025 07:19:35 -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=fm3; t=1762431575; x=1762517975; bh=aBt71oio3snTZOB3si+wuttcrO3jcNusWMQRceDjC5o=; b= CdAmvWyeI7bAzkKo2IAjHSnoWOLO8HsnBokjsXZINV7g6HsMK1faEeWavkND7C7z HD+Gb8AgXw8mjDJ/ViMBNsfaP5LYhCFRVhFJn/6Wp1iIFtQBvIMRkI1sL7UNd9tx mRcRxPdyoZzQimzKdCMrNx4decpQOtXHN5K7FFcS0x3NigOHnqAOw7CLk3g45hP3 GWrdr9jXe8Vyt9KHBc62VB48I/N4CPzlC0ovSVf0eMfaGh51b7sA8f+dkscPvnCR 2USsMVfLY2/Pf9N783joTtCHT0FZFpjF1d+RQd9/P+KZp/NI5yojvqChtx9zWGA6 MIsmu6ZwjvXlX/Ej0/j1Ig== 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=1762431575; x=1762517975; bh=a Bt71oio3snTZOB3si+wuttcrO3jcNusWMQRceDjC5o=; b=iuQc7BpUJqe/jqZ+9 5TH/uRYp2IOWBPWa1AnW8Lq0APo1i9kgi9V124fWOVA3LzBG56gkrzpINdRb4lfN u/MVjk2lYwxkf5fYTDPlbNc9qIRxRfRfqoNsOlINlrUw4MzD44bkO/+IJJxRPbRG 6XgzfWg+AIjOrzSbwGDv7WyFfojmbYvfdpKauaRSixh7Nm6umPqFBV9IpaGxymMT Ec1xvDakus2kgqKvOyFpUdf2T5PJH5qtcaEoK14Xbm4ffMtiGcv+T7W4e/9iAEe5 3bZD26QxJNugrBRu2eZYzZRKFu7RI3V/qU+9lx7hDAsnqlhiQ0yxFHVTIF9VOpUz 9ZiKA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdeggddukeeijeejucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucenucfjughrpeffhffvufgfjghfkfggtgfgsehtqhhmtd dtreejnecuhfhrohhmpedftfhofigrnhcuvfhomhhmihhnshculgfkoffuohfrngdfuceo ihhmshhophdrphhhphesrhifvggtrdgtohdruhhkqeenucggtffrrghtthgvrhhnpeehle ffteeigfevudetfedugedtudevledugeeugeelheeihfehgfdtkeevvefgleenucevlhhu shhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehimhhsohhprdhphh hpsehrfigvtgdrtghordhukhdpnhgspghrtghpthhtohepuddpmhhouggvpehsmhhtphho uhhtpdhrtghpthhtohepihhnthgvrhhnrghlsheslhhishhtshdrphhhphdrnhgvth X-ME-Proxy: Feedback-ID: id5114917:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Thu, 6 Nov 2025 07:19:34 -0500 (EST) Date: Thu, 06 Nov 2025 12:18:26 +0000 To: internals@lists.php.net Subject: Re: [PHP-DEV] [RFC] Context Managers User-Agent: K-9 Mail for Android In-Reply-To: References: Message-ID: <1CFE3E0B-23F5-4413-99DA-FAF308579A5A@rwec.co.uk> Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: imsop.php@rwec.co.uk ("Rowan Tommins [IMSoP]") On 5 November 2025 23:58:52 GMT, Bob Weinand wrote: >However, I still think the proposed approach is dangerous with respect to= forgetting the exitContext() call=2E When using manual handling=2E But yes= , I agree, that's a much more manageable concern=2E >And the onus of handling duplicate enterContext() and multiple exitContex= t() calls still lies on the implementer=2E The RFC does zero effort at addr= essing this=2E I think the relationship to Iterators is significant: if you put an iterat= or in a variable, it's perfectly possible to use it in two different foreac= h statements, or manually call the interface methods, and get very confusin= g results=2E But most of the time, you don't take a reference to the iterator at all, a= nd the same would be true of Context Managers: foreach ( $foo->iterate() as $item ) { =2E=2E=2E } with ( $foo->guard() as $resource ) { =2E=2E=2E } That said, it seems like it would be easy enough to add a mandatory state = check - a boolean property on the interface, and a check in the de-sugared = code: if ( ! $__mgr->canEnter ) { throw SomeError; } $__mgr->canEnter =3D false;=20 That would also give the implementation a choice of whether to reset it on= exit, or make the object strictly single use=2E That doesn't stop you manually calling the enterContext and exitContext me= thods in unintended ways, but that's actually true of RAII or Disposable de= signs, at least in PHP: there's nothing stopping you calling __construct or= __destruct as normal methods, and causing all sorts of unintended behaviou= r=2E Rowan Tommins [IMSoP]