Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129102 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 AC2BB1A00BC for ; Wed, 5 Nov 2025 23:27:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1762385272; bh=lirNf3WdGLyWmGDbLMnc32X4MFb5/uDwn6hJw4ytQHo=; h=Date:Subject:To:References:From:In-Reply-To:From; b=ZOiaYRpYWE67MPJosQ75YXQVZP3k+Al0S1HX5cbsbCxdVaH0BMH3QV6Glwgvc41xm K9UhrcunVd/0SOhoi/x4cruvvWR2xQ+zZQV0Ig/fmNZboU4IC75Vh/xv5G7s1mEjbx wFzJHq40F/Nh8A+CM08LGU871qVco75fGSYPxuXPUuw/xaJSQSyLH2kCH8hVv0E2Iu 76WG93EXU0w21/6XUkyNHEKxlJ1LZnaHIfsLSD4fRhG/wPHt7hmAay3gVZn/uI51Ox i12gHYYC6ALZqXFvXY3KZtP2NhjvksIJRF/FnHJdy1zK+yV06HYjgAL0CmVUu324// YfH4YlEjMt26w== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 37B361801EA for ; Wed, 5 Nov 2025 23:27:50 +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-b8-smtp.messagingengine.com (fout-b8-smtp.messagingengine.com [202.12.124.151]) (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 ; Wed, 5 Nov 2025 23:27:48 +0000 (UTC) Received: from phl-compute-01.internal (phl-compute-01.internal [10.202.2.41]) by mailfout.stl.internal (Postfix) with ESMTP id E6CFD1D001C0 for ; Wed, 5 Nov 2025 18:27:42 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-01.internal (MEProxy); Wed, 05 Nov 2025 18:27:42 -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=1762385262; x=1762471662; bh=ziqAumkpvQ+Y58LMCVkV7N9S18ms18gFNRHGZPzjhto=; b= os92XFwN12vxhXsOwtGK1MNY8gnw6Fg7GNIXPWG8o7HQr+6whcXPN/GRdVjnwpQ3 jULN3BOPuSHnue0faWL0UeDm8QCd5yVE70vVGPihNddLDqwzDjHD7xNQnqYbvjAQ 9S57r4UJEGqDYUvDkCQZcqQKMPL+VX0UeNvub9yCmSfDaXJg7GbaD84n4iDahj6v g4MokEQRe7N48pK6fmbL0iZtmgBdq518TxZdZU/8Bz1GFTbQVSUSVCM4EedehEEO k+l+CcUDqlT7SsBaZLmQOi/kzcXRXkpLFpIzzkeMcBMqsGNFAX12N0RaWe452roJ IUhGEvLlZa/fA+c5Lj4zPg== 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=1762385262; x=1762471662; bh=z iqAumkpvQ+Y58LMCVkV7N9S18ms18gFNRHGZPzjhto=; b=sIn01IiV99HNnG4qx QB4GtwOKnELs6eIIlllIlr9IR5h0iX35iSwnbcHTdnA8Iz8lsd3nscCZGng7HHvp VnKbEHCsFtwoVREl0VR/+9qNCBmNKnO96044oNY5nWm4QEpyAqjUhOavwPxss4+N CFoJA1ptbt6r0rG5kn9I3bdmSlZqMb8OZDO+r/eS1i/+RmiGpNV1a4NyDX9tZLYy Y0AEXlqNrrD85HjsyxM/+quTomN4/bveom7Nx33cmTld2ugmt36QIEeypG0S/nTA 0/F3zmiRYaw81EDfiMYl0W1JK3vz77hhCCVLZcs5Z1nHZfuG3lpYTmZ5bQAWBDDn cdHrg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdeggddukeehvddvucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucenucfjughrpefkffggfgfuvfhfhfgjtgfgsehtkeertd dtvdejnecuhfhrohhmpedftfhofigrnhcuvfhomhhmihhnshculgfkoffuohfrngdfuceo ihhmshhophdrphhhphesrhifvggtrdgtohdruhhkqeenucggtffrrghtthgvrhhnpeffke evudffuddvheejvdefkeelfedtudegfeehjeduheegieduffeggeegveefheenucevlhhu shhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehimhhsohhprdhphh hpsehrfigvtgdrtghordhukhdpnhgspghrtghpthhtohepuddpmhhouggvpehsmhhtphho uhhtpdhrtghpthhtohepihhnthgvrhhnrghlsheslhhishhtshdrphhhphdrnhgvth X-ME-Proxy: Feedback-ID: id5114917:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Wed, 5 Nov 2025 18:27:42 -0500 (EST) Message-ID: Date: Wed, 5 Nov 2025 23:27:41 +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 Content-Language: en-GB To: internals@lists.php.net References: 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 05/11/2025 22:38, Bob Weinand wrote: > I don't like that design, which effectively forces you to put safety > checks for all but the simplest cases onto the ContextManager > implementation. > And it forces the user to recognize "this returned object > DatabaseTranscation actually implements ContextManager, thus I should > put it into with() and not immediately call methods on it". (A problem > which the use() proposal from Tim does not have by design.) I think you may have missed the key distinction between a "Context Manager" (as designed by Python) and a "Disposable" (as used in C# and others): the Context Manager is not the resource itself, it exists only to meet the protocol/interface. In this code: with ( $dbConnection->transaction() as $handle ) {    $handle->execute('I am in the transaction'); } $handle is *not* the value returned by $dbConnection->transaction(), it's the value returned by $dbConnection->transaction()->enterContext(). One of the things that means is that if you just write $foo=$dbConnection->transaction() you can't accidentally run any methods on $foo, if all it has is enterContext and exitContext. It also means you can trivially wrap values that have no idea about context managers, without needing a load of extra proxy code; it's why the RFC can include implicit handling for resources; and why the generator example in the Future Scope section works. -- Rowan Tommins [IMSoP]