Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128342 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 85F421A00BC for ; Thu, 31 Jul 2025 12:34:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1753965151; bh=uM6iCSPwTnH9BDf71/9RUi7YnxH34J8UL0iWjucESJM=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=FB6Hectsw9YFXwStzZjVtgrNLDRHbskIxbuGO6S0lbl9ZTEYUKIleMY+rzqw0QrQ3 18NOFiOSEaIDuJdVL4dtwqbMrJ8gBzfFgTysK5wHWJFHQRyQEetud1EDB1ZhxUtRiP UgCcddCpx0X+bYAp1Ff3OQtSewDmgTNZVTNXKQ03lM4WVtQE/IUjtXP8yLVLHszZ0b o3GY4m6WIMw497s0fGO2uNaQGffBhT5Y28C9CYZ9oNbCqUskOBNC4bi+7MJfN0hq17 VG6TjgislR7TDCj0ML9NJJCfp04dG1YPYBSapJbBqtNBDVNPJb43m3nONTbYSzFlGe EpG3fBAVDyHEA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 91A1E18005D for ; Thu, 31 Jul 2025 12:32:30 +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.2 required=5.0 tests=BAYES_20,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, 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 mail-qt1-f181.google.com (mail-qt1-f181.google.com [209.85.160.181]) (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 12:32:20 +0000 (UTC) Received: by mail-qt1-f181.google.com with SMTP id d75a77b69052e-4aefb5c6750so175471cf.3 for ; Thu, 31 Jul 2025 05:34:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1753965241; x=1754570041; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=uM6iCSPwTnH9BDf71/9RUi7YnxH34J8UL0iWjucESJM=; b=W3Uh01YYloA/a62bwqZFkiNXQS6qleDRTlibRrX5Eeb46eN+/+7ziXy0qkEZknbV/6 2naQ570YYeJl2ATSDQyT7UlQqxRvQGwOmD05nrxuHOA5iXqsUc3dOwdQUjZ+dHFD7pZc F302PtT79Dbeepnn+y/xt+YNUJJcLZFM8Tzi+hxllZtP+MA3BxPlrmz9I0xRhDOwB+nI 2Qq7shT/K6aB2BqVXxom5Oo1H6I4deBgpsWV6XBqSLBQCzOaLM3VtF1q27S59RdHjV8d ASxa8Xs1YYxcDHIHvekwQHqEV5sKjuhxAZJwNnBRqD44MQF+/uep23hWaqouDOZCmZ0y SDEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753965241; x=1754570041; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=uM6iCSPwTnH9BDf71/9RUi7YnxH34J8UL0iWjucESJM=; b=fLUV5hwGbQ/GED66FOAthIPbuFLwYp/XroymsiCzm89PWJHll7w8YNkh5skvrGi7Da NOGD4LPwehK2u24IVrfHaeELDsGwYC9WG+xbrEWLrCc4eQlpGEC7VwIasj6Kv1D1TgMU Yaici8mp01sIQc1jin4k/7KX4EHWuN2pinohyCfSCbtnAntcWTjaNeRDrxv32tdsBXnL bhUWz9g7i758E5ods/pD63CJDqfB39A5fTcWWxiLpb2Horx6Cv6JpUp5Nv7hGc7+CPV0 JyLjyaaiz8EGybkirsPYwv+CggVRFNqGSxVrloVwSVK2ewXbQfZ425E6fN3i35U3tKeR x51g== X-Gm-Message-State: AOJu0YzODtqL9FoDCEea2KLM10vblqyu0HT39LgXaGr3iKGeLYZEuFb0 YGjqHT1r0Vg2OUvpzq9jqSPbXE+vZAZ32xFjyM7ZdP1A+WHN0opJX4FzML0dizavPlNx7vpr591 qbmxgtJ3en+bd4ceOlJ+6TNCAUKs4VTj5mIEwCw4= X-Gm-Gg: ASbGncuF0/Ry399PtvSBxViCT3VmvyYV4gFhEZYW1K2ELjtRLFQdWuQ9WbOXZIrKQLb VDiHO3jEp3y0gunj8ZsSU6f6GdkXB/RfE5kV9gb3QmRx3LPpYdaVk0koECOB4uQ7lmXFqZPk6Y+ h46GIjOO+dIHahhuX+1/MbsiHVR9CLrebGjvtBa+p/hovcmjv44b0OLAjAngWl+UpFwhHbJl4iE +7pghfcIqd7aY6F X-Google-Smtp-Source: AGHT+IE+8uQRtEatmwHM8ejewWvUTdCojyGa1gRDjobViIfFmvArLVGN/c00XeAW1VLKkrTz0IDE1OPMD70ua8GOjfY= X-Received: by 2002:a05:622a:4894:b0:4ab:8157:416b with SMTP id d75a77b69052e-4aedb9f343fmr124018701cf.26.1753965241371; Thu, 31 Jul 2025 05:34:01 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: In-Reply-To: Date: Thu, 31 Jul 2025 14:33:49 +0200 X-Gm-Features: Ac12FXzAPzhniOvnO3Zl6MyzUBjgr_mJ-MNfeEyMmdh5eJ20gdQ2EaZCZrHub7Q Message-ID: Subject: Re: [PHP-DEV] [DISCUSSION] User-land Throwable To: Dmitry Derepko Cc: PHP internals Content-Type: multipart/alternative; boundary="000000000000291803063b38db24" From: nicolas.grekas+php@gmail.com (Nicolas Grekas) --000000000000291803063b38db24 Content-Type: text/plain; charset="UTF-8" > Hello PHP Internals, > > 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. > > 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 > integration error + raised error around the current bridge implementation > (http client). > > There were several PHP applications with microservices architecture which > I had access to (docker + sources). > > 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 you > should extend Exception. But after that you still cannot override 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 interface now. > > ```php > class MyCustomThrowable implements Throwable {} > > // Fatal error: Class MyCustomThrowable cannot implement interface > Throwable, extend Exception or Error instead > ``` > > > 2. Make getTrace() non-final or provide alternative customization mechanism > The trace is stored in a private property, so you can use reflection to change it. new \ReflectionProperty(\Exception::class, 'trace')->setValue($e, $trace) Nicolas --000000000000291803063b38db24 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hello PHP Internals,

I would like to propose a discussion= regarding two current limitations in PHP's exception handling system t= hat I believe could be addressed to improve flexibility and developer exper= ience.

A few years ago I found that a library printed error traces w= rong.
After a little research I found that there was a mix of 3rd party = integration error + raised error around the current bridge implementation (= http client).

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

So having th= e 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 d= oes not allow you to manually implement Throwable. Instead you should exten= d Exception. But after that you still cannot override the getTrace() method= because it's final.

So my proposal is pretty simple: Remove bot= h restrictions.

1. Allow user classes to implement Throwable interfa= ce directly

User classes cannot implement the Throwable interface no= w.

```php
class MyCustomThrowable implements Throwable {}

= // Fatal error: Class MyCustomThrowable cannot implement interface Throwabl= e, extend Exception or Error instead
```


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

The trace is stored in a private property, so you = can use reflection to change it.

new \ReflectionPr= operty(\Exception::class, 'trace')->setValue($e, $trace)

Nicolas=C2=A0
--000000000000291803063b38db24--