Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129165 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 108AD1A0121 for ; Sun, 9 Nov 2025 15:08:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1762700890; bh=VGXBq/gYNEd/nLO3xZMxA8Mj+xElbIAokqUjmNQnW4w=; h=Date:From:To:In-Reply-To:References:Subject:From; b=i/9UDVp8rPZedl6LtC54DWHIx4qMO7bmb6QIyoFx21um+U1bjrXF4lCMvv3gPkFaB uSUR0zR6JXLe6M+0wUx71LjzPkWFsvMhTX2qJoJp4iB6/C9nNFfnRDJCDSRLAobqZR XMop+htQAvASb7hiuekNN59qn1IIEZ6hpIBTuM3pMB3Ym33pHRLW/+oTPD7YD+cisA SRg/3bqkf06aYQgOfH2fwT1C3mYU5Xlpb9L/1Le8cHst6+XVFHwNRocJd87ZNHoqM1 5VobqjxAkCN/qfIBl77plxxiXKE5HQKJFbMWg1qfQMxrIiNcP/HQnxlABD2fVw9XV/ 0VDP+qYzrHVsA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 99BC618037E for ; Sun, 9 Nov 2025 15:08:08 +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.9 required=5.0 tests=BAYES_40,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-b5-smtp.messagingengine.com (fhigh-b5-smtp.messagingengine.com [202.12.124.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 ; Sun, 9 Nov 2025 15:08:06 +0000 (UTC) Received: from phl-compute-04.internal (phl-compute-04.internal [10.202.2.44]) by mailfhigh.stl.internal (Postfix) with ESMTP id C1C1E7A019B for ; Sun, 9 Nov 2025 10:08:00 -0500 (EST) Received: from phl-imap-02 ([10.202.2.81]) by phl-compute-04.internal (MEProxy); Sun, 09 Nov 2025 10:08:00 -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=fm3; t=1762700880; x=1762787280; bh=DFk6KHdbb1jdM+55vafpv fZW22c9X8uLojL26KEdep4=; b=T/cu4vCE7L71HesgP+06k4Y/Mj1iUsJFIIHGX FSCplHvgELpbKyo7ptPoNSOceiNH3mubhQTlTojR/LAfCwSihv3KTQGKWVY8qnPb rrMTHEMzuXBxK4dYuxXo8yEhDnakE0bZqLhLF1a1PrRXH/+Z0S3hietGNp2W31aU SqMS3KHzHgNoDXPc1J3gYNWGe5iYodh2x2n7w1xnGaDOXnBr9YHIF9no7oopv0UH rJrviPOKH98enDZ0IWz9qNc0RH/FlxYMPvStvWm4052sUuJD+SQvzmOSegd0+Tfx yRQ+bR/Havad2gNmZyncKKVrpRWdecCOHvTqCRhyedSTji4xA== 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=1762700880; x=1762787280; bh=D Fk6KHdbb1jdM+55vafpvfZW22c9X8uLojL26KEdep4=; b=b8XDChJpAYlaNwKF0 Kd5xfUDawIoEQYUwsk4WJz7Phv9rsO5wKxYqxhJVRLirt2w4Oesb61PPJ/p2RwPT Clas35MlbYvVjNvqLRWarC8l2s2R5jmag3J+aitJXM6jOA2HIRIPijx/r5wHKYjf OZkc6CGxRWgfwtZ7rnWobZ/912SokX8Jm2FhFUAQn/JU2ZqEduMkLd6Qrt2m50X8 uPla1StCGlyV/TrNYOxsFeJerdiEg+LDyOa6RQ06qN9Y7ztFZdT6Ziv800qCfm6n q+KpzDKJasfXgX0gMpppGPPuFf9+kCO2l9Kgm8yheOLqsxR+kStayEgC7pQPhFFr aKBbA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdeggdduleehjeegucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhepofggfffhvffkjghfufgtgfesthejredtredttdenucfhrhhomhepfdfnrghrrhih ucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhmqe enucggtffrrghtthgvrhhnpedugedvlefgueegheefjeetffduveeltefhfeegjeffffel gedttdevkeegkedugfenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrih hlfhhrohhmpehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomhdpnhgspghrtghp thhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepihhnthgvrhhnrghlsh eslhhishhtshdrphhhphdrnhgvth X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 51AA8700054; Sun, 9 Nov 2025 10:08:00 -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: Sun, 09 Nov 2025 09:07:40 -0600 To: "php internals" Message-ID: <74abada6-cb34-490e-abeb-517e39b3ffa0@app.fastmail.com> In-Reply-To: References: Subject: Re: [PHP-DEV] [RFC] Context Managers Content-Type: text/plain Content-Transfer-Encoding: 7bit From: larry@garfieldtech.com ("Larry Garfield") On Wed, Nov 5, 2025, at 5:58 PM, Bob Weinand wrote: > You are right, I missed that there's an extra layer of nesting inside this. > I think the DatabaseTransaction example put me on the wrong thought path > because it just returned the connection it came from instead of a > dedicated nested Transaction object. (The enterContext method in that > example ought to include a startTransaction call.) > > However, I still think the proposed approach is dangerous with respect > to forgetting the exitContext() call. When using manual handling. But > yes, I agree, that's a much more manageable concern. > And the onus of handling duplicate enterContext() and multiple > exitContext() calls still lies on the implementer. The RFC does zero > effort at addressing this. > > Thanks, > Bob Bob, you seem to be focused on the "manual call" case. That... is not a case that exists. I cannot think of any situation where a user creates a context manager and then calls enter/exit context themselves that isn't a "stop that, you're doing it wrong" situation. By the same token, you *can* implement Iterator and then call current() and next() and valid() yourself... but odds are you're doing something wrong, and it's very easy to screw things up if you call those methods in the wrong order or too many times or whatever. If you implement Iterator, you're supposed to use it with foreach(). Doing anything else with it is "well technically that maybe works, but please don't." As Rowan noted, calling __construct() or __destruct() yourself is also possible, and can cause things to go sideways, and if they do then it's your own damned fault, don't do that. The same is true here. Someone manually calling enterContext and then not calling exitContext() is... simply not a use case that matters, because there's no good reason to ever do so. The only effort the RFC needs to make in this regard is say "don't do that." --Larry Garfield