Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128345 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 928C21A00BC for ; Thu, 31 Jul 2025 14:17:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1753971356; bh=XeRaOsWK5kFeTEnmiQlT/9sqaCuUzFkz2DOZ9GZFRxk=; h=Date:From:To:In-Reply-To:References:Subject:From; b=d/hfHYcgkI9QbM1wSRs8AxKIzuNbZqFV1cPRLOqUyjprEPVNByIEp5pB2j3RbU1hd YvNI+pb3vsxJ+iz0Y2Cn8KFcxCldbfOWCNRy7P7yFdXuWG7sE57gnOUDgA/91TlDRS Xpb0SeiuRKG7GDnRfOSCw10gOQ7HShCaLfjYpphHbQndyjUtBvU6xa0CQj/9vGo0+T K3l7TqF234fPGzoS/f7Piv54ZYxOiPSaPS5DpDHfrymzvNucIiz8qaZS6nt+/O20HI nF9UzUABYR85fY+l7OtBm636LJKojBW4wikfj9kd5x/UFRLrI8tODEyOUwZqCdFO49 azMDL5h65zBpw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 295BD18006C for ; Thu, 31 Jul 2025 14:15:55 +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_20,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,HTML_MESSAGE, RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from fhigh-b1-smtp.messagingengine.com (fhigh-b1-smtp.messagingengine.com [202.12.124.152]) (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, 31 Jul 2025 14:15:54 +0000 (UTC) Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailfhigh.stl.internal (Postfix) with ESMTP id 28A197A23A1 for ; Thu, 31 Jul 2025 10:17:36 -0400 (EDT) Received: from phl-imap-05 ([10.202.2.95]) by phl-compute-05.internal (MEProxy); Thu, 31 Jul 2025 10:17:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bottled.codes; h=cc: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=1753971456; x=1754057856; bh=TuXgxAd9X9 4Z6nAkl8tOAdoqXBnJFRTWMQX58Jh55BY=; b=SnWY+OA93QNhT7W3iK8eSg2uyM Xx+j3zuzTZ+/D8eiW9J108olsBJXnQndD8vytNhBRHBUSlz6zu5juiIK5PM7lI/D 3i2QV417liYN1FllTnup0gt4At24aLyS0rhzcpXbNmiWL+KZLkx3isPuy1pXGmZg zYzcUzPTcCj5iZoAmgHTT4ejV+lus/7lnEGyPjEPrsHphvvoxBM1z+oJ1tLgLk1v 1/Sr40t93Q8C5EhTCFyojN0MWs46bRT9PfYij4r84dNMTv8d7JyhWopIIsQyJ5ns u6VnFX0eKDg3lnDkPVgSUk17OpSoEIMaSSVwhRrnX0lGgWNme3rOpuJXB9Ag== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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= 1753971456; x=1754057856; bh=TuXgxAd9X94Z6nAkl8tOAdoqXBnJFRTWMQX 58Jh55BY=; b=nM1HW7l4iGqG58ErZA1s+29Lf0PJAJgce1r1p7ZCjYja6oxgpF/ B0bdGcjqh09dFiRMtOtFfMRBQTW2RCUPI7C09RdEop8b3x2+0XixtrTiK5OBRLcY Ezwy8nIIev96ZHbHVDLvtRiqqvNqrCXwHVmOowI2NNCqwInCUKthqCkXwf2fiB3i /9s24I9jGBL1BfmRCJNVr/hI7+C1gp+mAlNZhby3j27FMQMrxLTS8axHQYA3AIku XIxI7Wlw5v1r6RsEYoORXMcR+Bqevf+Ob83N5NpIkKxgAj3L7cmM62qFlmlmiIKb gkco76O4ZS5UVFGkMFPLZMbIUdffNeSpFFw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgddutddutdefucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucenucfjughrpefoggffhffvkfgjfhfutgesrgdtreerre dtjeenucfhrhhomhepfdftohgsucfnrghnuggvrhhsfdcuoehrohgssegsohhtthhlvggu rdgtohguvghsqeenucggtffrrghtthgvrhhnpedtueejtdethfeulefhtdelieduteelff dtudelheffgedtieehhfelieejgfevgeenucevlhhushhtvghrufhiiigvpedtnecurfgr rhgrmhepmhgrihhlfhhrohhmpehrohgssegsohhtthhlvggurdgtohguvghspdhnsggprh gtphhtthhopedupdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehinhhtvghrnhgr lhhssehlihhsthhsrdhphhhprdhnvght X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 4FC371820074; Thu, 31 Jul 2025 10:17:35 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 X-ThreadId: AzoCpASj9aCJ Date: Thu, 31 Jul 2025 16:17:11 +0200 To: internals@lists.php.net Message-ID: <68de724e-61f2-4ee1-bd5d-fbb35935041c@app.fastmail.com> In-Reply-To: <5A451842-1B55-4ADC-A747-C897FB3CE323@cschneid.com> References: <5A451842-1B55-4ADC-A747-C897FB3CE323@cschneid.com> Subject: Re: [PHP-DEV] [RFC] Optional Catch Block Body Content-Type: multipart/alternative; boundary=1c1ab1fe5e17429a836ea47614a30435 From: rob@bottled.codes ("Rob Landers") --1c1ab1fe5e17429a836ea47614a30435 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Thu, Jul 31, 2025, at 15:32, Christian Schneider wrote: > Am 31.07.2025 um 09:10 schrieb Rob Landers : > > I can see something like this being useful in niche applications. Fo= r example, I have a proxy generation class that creates something like t= his: > >=20 > > public function remoteCall() { > > $this->operation =3D nameof($this->remoteCall(...)); > > $this->arguments =3D func_get_args(); > > throw new SpecialException(); > > } > >=20 > > This SpecialException gets caught to let me know the application has= consumed the one-use proxy. Using it looks something like=20 > >=20 > > rpc(fn(RemoteObject $o) =3D> $o->remoteCall()); > >=20 > > which just provides type-safe rpc at the expense of some boilerplate. > >=20 > > I also use empty exceptions to "jump" the stack when my framework kn= ows there is nothing more to do until outside events happen. I think I c= ould probably use fibers to do the same, but if the user is using a fibe= r library; there is no guarantee they'll play nice together. This is tru= e with exceptions as well, but the user has direct control over exceptio= ns (do not catch Throwable, for instance). >=20 > I'm not 100% sure I understood your examples but this smells like you = are using exceptions for flow (or maybe state?) control which I'm not su= re I would encourage. >=20 > Regards, > - Chris >=20 It's explicitely to jump/unwind the stack -- PHP has no other way (other= than suspending a fiber or yielding a generator) to jump/unwind the sta= ck to a given point. Fibers are the superior way here, but even then, th= rowing from the fiber is still the best way to terminate it and force a = GC of the stack there. This is basically using it as a longjmp (in C ter= ms) which PHP doesn't have any other way to express. They're not used fo= r flow control, or state. They merely force PHP to unwind the stack to a= known place (all possible side-effects have already been done and it is= either throw -- or wait for an external event, potentially forever -- w= hich consumes memory and a thread). =E2=80=94 Rob --1c1ab1fe5e17429a836ea47614a30435 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
On Thu, Jul = 31, 2025, at 15:32, Christian Schneider wrote:
Am 31.07.2025 um 09:10 schrieb Rob Lande= rs <rob@bottled.codes>:
> I can see something like this being useful in niche applic= ations. For example, I have a proxy generation class that creates someth= ing like this:
> public function remot= eCall() {
>   $this->operation =3D nameof($thi= s->remoteCall(...));
>   $this->arguments =3D= func_get_args();
>   throw new SpecialException(= );
> }
> This SpecialExce= ption gets caught to let me know the application has consumed the one-us= e proxy. Using it looks something like 
<= div>> rpc(fn(RemoteObject $o) =3D> $o->remoteCall());
> which just provides type-safe rpc at the expe= nse of some boilerplate.
> I also use = empty exceptions to "jump" the stack when my framework knows there is no= thing more to do until outside events happen. I think I could probably u= se fibers to do the same, but if the user is using a fiber library; ther= e is no guarantee they'll play nice together. This is true with exceptio= ns as well, but the user has direct control over exceptions (do not catc= h Throwable, for instance).

I'm not 100% sure I= understood your examples but this smells like you are using exceptions = for flow (or maybe state?) control which I'm not sure I would encourage.=

Regards,
- Chris


It's explicitely to jump/unwind the st= ack -- PHP has no other way (other than suspending a fiber or yielding a= generator) to jump/unwind the stack to a given point. Fibers are the su= perior way here, but even then, throwing from the fiber is still the bes= t way to terminate it and force a GC of the stack there. This is basical= ly using it as a longjmp (in C terms) which PHP doesn't have any other w= ay to express. They're not used for flow control, or state. They merely = force PHP to unwind the stack to a known place (all possible side-effect= s have already been done and it is either throw -- or wait for an extern= al event, potentially forever -- which consumes memory and a thread).

=E2=80=94 Rob
--1c1ab1fe5e17429a836ea47614a30435--