Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128256 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 EF65C1A00BC for ; Mon, 28 Jul 2025 12:24:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1753705370; bh=fLG/nb0UJnqe35uoCwfCilcWfl1BhO3IMM/GCro32ao=; h=Date:From:To:In-Reply-To:References:Subject:From; b=W/UptO7JABDEIhQwcFhYARA3QU7eXZmAPwFoiF6Xf3L0xP3Zrqi/GTyersxxuBp3X gn/GBOZkRvqX2jWv0O29hBtlQX5DNp78dF2UtjUMr3k53llSXJzzcFh5tTdcaU8nOG Bxu0rS8xEp4+A7ZdTgVmWXqR750a5Mxl41KJ4ZP3OQtMhBxYPOyd+cLKFk+gQS6UCk uSdbwjZYZbOgSLHzC4j/2cLOAhAP3KlORIPKSFEfZJR2VsDwGA92WY7/2cfjbUaKpT CuX27gebDS7Jv7Au4WJ5La5coBmUUfvh4EEwBVo4Z+/wK/VUNg5BxJ4grslEt87U1k A0hCVwe9NK2kQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 9BF0F1801DD for ; Mon, 28 Jul 2025 12:22:49 +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,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-a4-smtp.messagingengine.com (fhigh-a4-smtp.messagingengine.com [103.168.172.155]) (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, 28 Jul 2025 12:22:49 +0000 (UTC) Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailfhigh.phl.internal (Postfix) with ESMTP id 0AE8F1400192 for ; Mon, 28 Jul 2025 08:24:32 -0400 (EDT) Received: from phl-imap-05 ([10.202.2.95]) by phl-compute-05.internal (MEProxy); Mon, 28 Jul 2025 08:24:32 -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=1753705472; x=1753791872; bh=truGAC1Rom 2pr2MEu161hrzfNkFGMOvzVcEZzBKqqhs=; b=Jf1TsutTuz0TNcACY5YKXOITas sNJm7sxjZ7fhcdZfQAPyqPGZnT/CuQfRP4a1A/FUhAmUuXKdGHBvcdHeSsXmrig1 tskwwS4ocHnYFTR1jC8h94ooVArJGHt2/Q8dlbIFZkDEeWLx9Fzk+8+YIXj68+Uv /+kLu8/dCtAMfj2naphdG/L7aPfL6OvNSXLkXOEwUufNgdJcCwkkUdMReyojoAAt xuZVvI0Wq/O1bzFjoM9uR1fPlXBtistAKysNBW2/AWtfmVre1BgB2XxIly18qB6u 7haOQda7cZSoHM0HxtujwpNHxkVUYkOuu0nnbQ3T1wXF8QiT0PnWKWO0FbNw== 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= 1753705472; x=1753791872; bh=truGAC1Rom2pr2MEu161hrzfNkFGMOvzVcE ZzBKqqhs=; b=in6ftAE3q2HAz2D6FONU2CLqrBfgWxT/Iq55zbNX80V5jb0CN5h bciUc/ur7Nt7s8D0rXNfd/Yo4fkAGcEcI5mgTOtsMZNEWZhz1Jo3Kx7A7DsNT+ae IdfxajIxN99RTK4Oel4nS/sO1i9G2Bn0N97tlNbVebG9jNhrI7Lef7z5icQ15bTv wWBBWAbM+sfL2XWFhYAQegxlndVJkD/oVq9z4W7x+3BftgWzRLDNfs5abZNYR1oc 1sO68QYnHlglNPOPqXd6i3Hz1BGw7M7b8rC/8/llchPAgAOdhBdtP4LKCu++OyB8 QTifwEUCS7+fUQrBhoPwPuhOWIm5tY8qsog== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgdelvdduiecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecunecujfgurhepofggfffhvffkjghfufgtsegrtderreertd ejnecuhfhrohhmpedftfhosgcunfgrnhguvghrshdfuceorhhosgessghothhtlhgvugdr tghouggvsheqnecuggftrfgrthhtvghrnheptdeujedttefhueelhfdtleeiudetlefftd duleehffegtdeihefhleeijefgveegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghr rghmpehmrghilhhfrhhomheprhhosgessghothhtlhgvugdrtghouggvshdpnhgspghrtg hpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepihhnthgvrhhnrghl sheslhhishhtshdrphhhphdrnhgvth X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id A1A111820074; Mon, 28 Jul 2025 08:24:31 -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: T75a531484929f33e Date: Mon, 28 Jul 2025 14:24:11 +0200 To: internals@lists.php.net Message-ID: <7d83b833-6432-4a86-8e11-b4199fa92430@app.fastmail.com> In-Reply-To: References: Subject: Re: [PHP-DEV] [DISCUSSION] User-land Throwable Content-Type: multipart/alternative; boundary=b60383ce236143b29e986db1fbca2d57 From: rob@bottled.codes ("Rob Landers") --b60383ce236143b29e986db1fbca2d57 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Mon, Jul 28, 2025, at 11:41, Dmitry Derepko wrote: > Hello PHP Internals, >=20 > I would like to propose a discussion regarding two current limitations= in PHP's exception handling system that I believe could be addressed to= improve flexibility and developer experience. >=20 > A few years ago I found that a library printed error traces wrong. > After a little research I found that there was a mix of 3rd party inte= gration error + raised error around the current bridge implementation (h= ttp client). >=20 > There were several PHP applications with microservices architecture wh= ich I had access to (docker + sources). >=20 > So having the message and traces I'd like to have an error chain as it= can be done chaining several errors through a new Exception(previous: $= e). > But PHP does not allow you to manually implement Throwable. Instead yo= u should extend Exception. But after that you still cannot override the = getTrace() method because it's final. >=20 > So my proposal is pretty simple: Remove both restrictions. >=20 > 1. Allow user classes to implement Throwable interface directly >=20 > User classes cannot implement the Throwable interface now. >=20 > ```php > class MyCustomThrowable implements Throwable {} >=20 > // Fatal error: Class MyCustomThrowable cannot implement interface Thr= owable, extend Exception or Error instead > ``` >=20 >=20 > 2. Make getTrace() non-final or provide alternative customization mech= anism >=20 >=20 > Exception traces cannot be overridden now. >=20 > ```php > class MyCustomThrowable extends Exception { > function getTrace() { return []; } > } >=20 > try { throw new MyCustomThrowable(); } > catch (Exception $e) { var_dump($e->getTrace()); } >=20 > // Fatal error: Cannot override final method Exception::getTrace() > ``` >=20 >=20 > There are some points about the feature: >=20 > - Microservice support: Preserve traces across service boundaries > - Proxy/decorator patterns: Maintain original error context through wr= appers > - Unified error handling: Any object implementing Throwable can be thr= own consistently > - Testing improvements: Create mock throwables for unit tests > - Performance optimization: Avoid deep call stacks in generated traces >=20 >=20 > What do you think about it? Are there disadvantages or points to have = the exceptions in the current state? > -- > Best regards, > Dmitrii Derepko. > @xepozz Wouldn=E2=80=99t a better approach be to allow serializing/deserializing= exceptions? =E2=80=94 Rob --b60383ce236143b29e986db1fbca2d57 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable

On Mon, Jul 28, 2025, at 11:41, Dmitry Derepko wrote:
Hello PH= P Internals,

I would like to propose a discussi= on regarding two current limitations in PHP's exception handling system = that I believe could be addressed to improve flexibility and developer e= xperience.

A few years ago I found that a libra= ry printed error traces wrong.
After a little research I found= that there was a mix of 3rd party integration error + raised error arou= nd the current bridge implementation (http client).

=
There were several PHP applications with microservices architecture= which I had access to (docker + sources).

So h= aving the message and traces I'd like to have an error chain as it can b= e done chaining several errors through a new Exception(previous: $e).
But PHP does not allow you to manually implement Throwable. Inst= ead you should extend Exception. But after that you still cannot overrid= e the getTrace() method because it's final.

So = my proposal is pretty simple: Remove both restrictions.

1. Allow user classes to implement Throwable interface directly=

User classes cannot implement the Throwable in= terface now.

```php
class MyCustomThr= owable implements Throwable {}

// Fatal error: = Class MyCustomThrowable cannot implement interface Throwable, extend Exc= eption or Error instead
```


2. Make getTrace() non-final or provide alternative customization = mechanism


Exception traces canno= t be overridden now.

```php
class MyC= ustomThrowable extends Exception {
    function getT= race() { return []; }
}

try { throw n= ew MyCustomThrowable(); }
catch (Exception $e) { var_dump($e-&= gt;getTrace()); }

// Fatal error: Cannot overri= de final method Exception::getTrace()
```

=

There are some points about the feature:
<= br>
- Microservice support: Preserve traces across service bou= ndaries
- Proxy/decorator patterns: Maintain original error co= ntext through wrappers
- Unified error handling: Any object im= plementing Throwable can be thrown consistently
- Testing impr= ovements: Create mock throwables for unit tests
- Performance = optimization: Avoid deep call stacks in generated traces

<= /div>

What do you think about it? Are there disadvant= ages or points to have the exceptions in the current state?
<= div>--
Best regards,
Dmitrii Derepko.

Wouldn=E2=80=99t a better approach be to allow serializing/deserializ= ing exceptions?

=E2=80=94 R= ob
--b60383ce236143b29e986db1fbca2d57--