Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128248 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 E8CA81A00BC for ; Mon, 28 Jul 2025 09:41:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1753695573; bh=d6B0DPZ12FAWEp3Qvy4BVn33muEOVU9rytFiJEHrBOM=; h=From:Date:Subject:To:From; b=J8bSTz3Lesoay4Tx2rpwTJb5ghbV0ucgiS5o4lJ42wQxOLynUlU5XUB2qZfl3nNVa CjYCBY/yJP6ZvXNwX48nNp70PuH97zvwYAYwep2y+8u2njPARgOr08JRdf4w2oiD1i nK6AMrnDbhL2+0YbIATFfiQWeezrOqFd2iheAHiS0qa4V7bmccmEdMxab7efVHCDRP yCVk4GetuYz5zkfHdLmBnBATjC2iz39xc8zlAFidoPMrq+o+g8/CUOVjSKpPD192qP Y1l0L37BtKvgev/2p3pXAXQyOyf4FB4UFhu1z8V78K9rX8i+I+xiRxKHcPIP3MEPei MJK+A2uHP87Ug== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 8BB22180583 for ; Mon, 28 Jul 2025 09:39:32 +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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,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-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) (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 09:39:32 +0000 (UTC) Received: by mail-pj1-f42.google.com with SMTP id 98e67ed59e1d1-31ecdf5faaeso986103a91.0 for ; Mon, 28 Jul 2025 02:41:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1753695674; x=1754300474; darn=lists.php.net; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=cwUFg3JPTKXFbgpCSCUSWa8vbznW9Hi+WrfUPD9/Y9I=; b=Sr7Susf4+X60BJtGjo7keOT5/DM5TSBK1imCEH3ROvlnO1ERWF+jtJpcsDOwXx2tsD WJWJiKc48y8V0XKYdTNVn7cKP4ylakRbfgpvgO3LLCPl7xWs5TrK+elL4sWeYjRD8yE8 lx7RNJcHk2BzD2TA1aWjvw8LTuiagnXDAE1IZFmL9EATiRG+9jrgc7pgWRAD89odwEoZ StfYSd7ECJy+HnnbLIKWmksoqaA9I4ZO1PYl01qTzyU8rFNmXHGc2mJQYWWhCEAzNuCw 5wsoJ/iOGZ+ydf/y7K67R4uAgsu83wj6V/+oH8MgcrQemD7kjB0vyKFmryhYIlnxv8cD VgnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753695674; x=1754300474; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=cwUFg3JPTKXFbgpCSCUSWa8vbznW9Hi+WrfUPD9/Y9I=; b=Pn09PdMZpPw/QH0WwwejrJKfIeiEcACqALFGaWgeF6VgNSu5J7ScLLdQbn4crYbjTN CGYxyW0Z0af4rTXw0aHsQVlM/Rpyk42HJlzK1mTR5fWFkPervZFQUeLdkTk06zlrnG0Y 1KFUKisgSBp0ZHSz143SshxBUwZx6whpluI/Co6kzi/9q7irG27St2jw868a3ZW9wURA gk6g/7MQflpHszfdm9di2j0cyAo6D91GDO9KAgMEdoe0HXMCRW9ED+tuHjdC5K5irGyf 3dMqGXAcHGriLBekDLCUntZDLxZ35N4qc7oaKf0uSxWMdW8njxBNmqXYIhLszXrDzpBL TcuA== X-Gm-Message-State: AOJu0YwoKVz4Ukz7+DndvAqkDGkLW403QWhqzInHVhDfJgVoNZjFHi/l lXy7moWAN4GbAsU2SDPg7fQX59DWfBZNOzqWo6mdYh9qGuXW9CyqUd+xMZdFkI7vBCjrNCle9w6 3ekGeQAbMEs5MZwzAIIvCPDnN3DYHYEHns5uB4gU= X-Gm-Gg: ASbGncteoW2Jr04txntdVRhDksn5C2BaYax0nOJH/YANEU6l4rZpazXQLlfKf+aOU8g HJIsGq1gGWWBS6pYD8wvp7a3LwO6mSvT5tYNwEYyiHoYXuzMzMW5GRtugJhzfO3Fq9O0/8JXd46 wljlnWM0AvqHrvEhmD7oM0XqL0TrlsbPe52wNV57i64Dyor3J7zmzLuIo/VJDD1eemIR5c3MfK/ U3WHiIw X-Google-Smtp-Source: AGHT+IGVMK7oEQ/W387wELMFo3ovwX+J0eJ6beTjLnEpJHqTSBVl6YIVWy1GmOl3y+86GtNfuJRoEFlBWNmo+/mh1pM= X-Received: by 2002:a17:90b:38ce:b0:313:f83a:e473 with SMTP id 98e67ed59e1d1-31e778a4218mr15318352a91.15.1753695673794; Mon, 28 Jul 2025 02:41:13 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 Date: Mon, 28 Jul 2025 12:41:02 +0300 X-Gm-Features: Ac12FXyMFgWFS94eYyY877QGg4BDaR3YqMD0kVvyKKkFa9WxE2XJezVL0n5vtY8 Message-ID: Subject: [PHP-DEV] [DISCUSSION] User-land Throwable To: PHP internals Content-Type: multipart/alternative; boundary="000000000000ae480c063afa17aa" From: xepozzd@gmail.com (Dmitry Derepko) --000000000000ae480c063afa17aa 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 Exception traces cannot be overridden now. ```php class MyCustomThrowable extends Exception { function getTrace() { return []; } } try { throw new MyCustomThrowable(); } catch (Exception $e) { var_dump($e->getTrace()); } // Fatal error: Cannot override final method Exception::getTrace() ``` There are some points about the feature: - Microservice support: Preserve traces across service boundaries - Proxy/decorator patterns: Maintain original error context through wrappers - Unified error handling: Any object implementing Throwable can be thrown consistently - Testing improvements: Create mock throwables for unit tests - Performance optimization: Avoid deep call stacks in generated traces What do you think about it? Are there disadvantages or points to have the exceptions in the current state? -- Best regards, Dmitrii Derepko. @xepozz --000000000000ae480c063afa17aa 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 handli= ng system that I believe could be addressed to improve flexibility and deve= loper experience.

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

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

S= o having the message and traces I'd like to have an error chain as it c= an be done chaining several errors through a new Exception(previous: $e).But PHP does not allow you to manually implement Throwable. Instead you s= hould extend Exception. But after that you still cannot override the getTra= ce() method because it's final.

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

1. Allow user classes to implement Throwa= ble interface directly

User classes cannot implement the Throwable i= nterface now.

```php
class MyCustomThrowable implements Throwable= {}

// Fatal error: Class MyCustomThrowable cannot implement interfa= ce Throwable, extend Exception or Error instead
```


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

<= br>Exception traces cannot be overridden now.

```php
class MyCust= omThrowable extends Exception {
=C2=A0 =C2=A0 function getTrace() { retu= rn []; }
}

try { throw new MyCustomThrowable(); }
catch (Excep= tion $e) { var_dump($e->getTrace()); }

// Fatal error: Cannot ove= rride final method Exception::getTrace()
```


There are some p= oints about the feature:

- Microservice support: Preserve traces acr= oss service boundaries
- Proxy/decorator patterns: Maintain original err= or context through wrappers
- Unified error handling: Any object impleme= nting Throwable can be thrown consistently
- Testing improvements: Creat= e mock throwables for unit tests
- Performance optimization: Avoid deep = call stacks in generated traces


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