Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:130500 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 AE20C1A00BC for ; Mon, 30 Mar 2026 18:56:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1774897020; bh=eT4GWC8BMyyeK7NsjdLPvIdtyTzitezE2j2nxpQYE7Y=; h=Date:From:To:In-Reply-To:References:Subject:From; b=X81YZ1GWd9ZC3oijsYHRYfd4rnheokgnTIQ43PuWJJqUAxE5QzT9IsrHIViPL6nhT qiIA+12aDYysylWTCY0DME1tEeHfPmjxEZ9UH94mAzpPWrsHiUYnj7u+khgaqwsGKE BtSlXfRafMLQfCsOhjYHCzyqEkmfZqYecExHHpZbngUdShYTeQYlvnzbOhjimfchOg xMPyvhy+3N7KaYgIL4psDDL3mdZo6Wc00Ai1w/Pc3wUSZFFgVDDVq/QymqBFzr90Wx M0/05DcTx8ShGCHK6lZqSoSJPqxWjRwvgVsVcUz2h5hLxdiXvlfryaq3/Oxn2wBn3t ddBxCL1HN0fUA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 82D76180080 for ; Mon, 30 Mar 2026 18:56:59 +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_NONE autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from fout-b1-smtp.messagingengine.com (fout-b1-smtp.messagingengine.com [202.12.124.144]) (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 ; Mon, 30 Mar 2026 18:56:49 +0000 (UTC) Received: from phl-compute-04.internal (phl-compute-04.internal [10.202.2.44]) by mailfout.stl.internal (Postfix) with ESMTP id 2318E1D0013C for ; Mon, 30 Mar 2026 14:48:50 -0400 (EDT) Received: from phl-imap-02 ([10.202.2.81]) by phl-compute-04.internal (MEProxy); Mon, 30 Mar 2026 14:48:50 -0400 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=fm1; t=1774896529; x=1774982929; bh=qFtoKbrFltjVxLCm6goP+ KPHCrast1GhHYPJ+kVSd80=; b=IUuLrg7ZU7c2Bn9aQFmOWzrp3zTas5459RN+g k9I+uhV0+q0zV/2JZgaeKEMr9Mwi53FUq0tmj11HId2DL7kSaOOTtdlDrFyYO70h VFZf6p/ir6c5/wfl7aFGRYdiwgZVWb95NFKxdTcqmTQuq19QO8DpoqT84v+81IX3 gxWSE8WJ4J9Z5Ion9D9fVlWv8CIZhverzu62tkhNAMezV3UHZHAR5FofvNQ1Qt2j eNI78NaDWhN75hYSShYrgxLwoOh27mVK7WyDZk/uCuyWxtkPSxTOYbE+HrCqGuXJ jcveVwUe/wLACM7hMA4Gjb3NdSFifzHiXBCnwRIN713VS1gmw== 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=1774896529; x=1774982929; bh=q FtoKbrFltjVxLCm6goP+KPHCrast1GhHYPJ+kVSd80=; b=bzml53Np0y1Sgg94z iZLVXhDq7Xp3neWS+SIV6I4APYA1pY9JZAvrqzwZXM8UQgMY58Zj05XwpRMamUb2 //jYRkHfRSRRkFmKkB8oIeEWkG8jlW/u4/rk8Xho5Muk1HgErObTMYYMNEuXSSbI 8uCBe3T6NcBmwRppHuPp/Ms0W1cJTuSwrC55dfY0UqgUTliE/6a/35pzcFXny09Y uq2HwZGSUr/FaWEWIHKz0YiDe4R6yzKaKUj6wMs+87m1GoYZtWgUzN6+Pa7fd07R zjhq171Y/Vq4k9MzCzLIeJBNPvrzx0MY8xklkjd4fStOGgT1T7SG1YkwovewDAIH 4/NMw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgdeffeeljeegucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhepofggfffhvffkjghfufgtgfesthhqredtredtjeenucfhrhhomhepfdfnrghrrhih ucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhmqe enucggtffrrghtthgvrhhnpeeugfetieejueevffdulefhhfethfekvedtueevgfffvdef iedvtefgheevteelffenucffohhmrghinhepphhhphdrnhgvthenucevlhhushhtvghruf hiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehlrghrrhihsehgrghrfhhivghl ughtvggthhdrtghomhdpnhgspghrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpd hrtghpthhtohepihhnthgvrhhnrghlsheslhhishhtshdrphhhphdrnhgvth X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 97AA7700065; Mon, 30 Mar 2026 14:48:49 -0400 (EDT) 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: Atmh9k-BTBuN Date: Mon, 30 Mar 2026 13:48:05 -0500 To: "php internals" Message-ID: <8bf1b0a7-7771-4f81-b92c-49bb019f7f9d@app.fastmail.com> In-Reply-To: <5d96fca3ca5418e6e9e5d8871b26477f@bastelstu.be> References: <5d96fca3ca5418e6e9e5d8871b26477f@bastelstu.be> Subject: Re: [PHP-DEV] [RFC] Context Managers Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: larry@garfieldtech.com ("Larry Garfield") On Sun, Mar 29, 2026, at 6:14 AM, Tim D=C3=BCsterhus wrote: > Larry, > > Am 2026-03-22 19:19, schrieb Larry Garfield: >> Arnaud and I have made a number of changes to the RFC that should mak= e=20 >> it sleaker and more consistent. The notable ones (that impact=20 >> behavior) are as follows: > > =E2=80=9CSleaker=E2=80=9D is not a word my dictionary understands. Was= this a typo for=20 > =E2=80=9Csleeker=E2=80=9D in the sense of =E2=80=9Crefined=E2=80=9D? Yes, typo. Sleeker in the sense of "fewer bumpy parts on it."=20 >> 1. We went back and forth on the `continue` question several times,=20 >> before coming to the conclusion that `continue` is a tool for looping=20 >> structures only. That `switch` also uses it is just `switch` being=20 >> silly because reasons, and there is no reason `using` must inherit it= s=20 >> weirdness. Therefore, `continue` inside a `using` block now means=20 >> nothing at all. `continue` will ignore it, the same way it ignores a= n=20 >> `if` statement. > > I fail to see how =E2=80=9Cmaking break; and continue; behave inconsis= tently=E2=80=9D is=20 > making the RFC (and by extension) the language any more consistent. In=20 > this following example snippet it's not at all obvious that the `break= `=20 > is behaving incorrectly by targeting the `using()` with `continue`=20 > targeting the `foreach()`, despite both using the same =E2=80=9Cnumber= =E2=80=9D: > > $processed =3D 0; > foreach ($entries as $entry) { > using ($db->transaction()) { > switch ($entry['type']) { > case 'EOF': > break 2; > default: > if (should_skip($entry)) { > continue 2; > } > > $db->insert($entry); > } > } > > $processed++; > } > > I'm also noticing that the RFC still does not explain *why* the decisi= on=20 > for `break` to target `using()` has been made. For your reference, my=20 > last email asking that question is this one:=20 > https://news-web.php.net/php.internals/129771. I didn't receive a repl= y=20 > to that email either (and neither do the list archives have a reply). I'm pretty sure I did explain in this thread somewhere... In short, we = want a way to be able to terminate the using block early in a success ca= se. An error case is easy (throw), but for a success case we cannot use= return, as that will return from the function. Technically "goto and your own label" would work, but I really hope we d= on't need to get into a discussion about why making goto the only way to= solve something is a bad idea... break is the natural keyword for that, as it already means "stop this co= ntrol structure and go to the end of it." continue means "stop this iteration of a control structure and go to the= next one." But in this case, there is no next one. switch makes it an= alias for break, for whatever reason lost to history, but given that it= now throws a warning that seems to now be considered a mistake, so we d= on't see a reason to propagate that mistake. >> 2. Several people (including us) were uncomfortable with using a=20 >> boolean return from the exitContext() method. While that is what=20 >> Python does, it is indeed not self-evident how it works. (Should tru= e=20 >> mean "true, I'm done" or "true, rethrow"?) We debated using an enum=20 >> value, but that appeared to be too verbose. >>=20 >> Instead, we decided that exitContext() should return ?Throwable, whic= h=20 >> is the same thing it is passed. In a success case, it is passed null= . =20 >> In a failure case, it is passed a throwable. So it can then return=20 >> null (meaning "we're done, nothing else to do here") or a throwable,=20 >> which will then get thrown. Since in most cases an error should be=20 >> allowed to propagate, it means simply calling `return $exception` at=20 >> the end of the method will "do the right thing" 95% of the time. =20 >> Simple and easy and self-documenting. (If there's a reason to wrap a= nd=20 >> rethrow the exception, do that and return the new exception. Or to=20 >> swallow the exception and not propagate it, return null.) > > That sounds like a =E2=80=9Cthrow=E2=80=9D statement with extra steps = [1]. While nothing=20 > stopped you from writing `throw new SomeException();` within=20 > `exitContext()` with the `bool` return value, it at least *encouraged*=20 > you to not replace the original Exception with another Exception=20 > entirely and to just make a decision between =E2=80=9Csuppress=E2=80=9D= or =E2=80=9Cnot=20 > suppress=E2=80=9D. Now `return` is completely equivalent to `throw` (a= t least as=20 > long as `exitContext()` doesn't contain a `catch()` itself) adding eve= n=20 > more layers of =E2=80=9Cusing() is magically including behavior of oth= er=20 > language constructs=E2=80=9D that will be hard to reason about for hum= ans and=20 > machines alike. If you have an alternate suggestion for how to achieve this functionalit= y, now is the time to propose it. Behaviors in the order they're likely to happen (I'd expect): - Success case, there is no exception - Keep propagating the exception. - The exception stops here. - We're catching the exception and wrapping it in another exception with= more useful data on it (exceptions can do that), and then throwing that. The setup we have now solves all four cases with fairly self-evident cod= e, and handles the first two cases in the exact same code so most people= won't need to really think about it. If you have a better suggestion, = please do share. --Larry Garfield