Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127229 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 9ED1A1A00BC for ; Mon, 28 Apr 2025 20:30:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1745872080; bh=QOaVRB89FtWNhLtx+V7RQSXtJr+9DrojXRjIw3jQKro=; h=Date:Subject:To:References:From:In-Reply-To:From; b=BP641Dc36EYRfo7a8Dgpfs/oj6lvMiX3VqDKY3BRMsmWMJixHvnG6YGr0zKGvQ8Uy I6ItxQF1fgRSFuQa2o6SILmqImOArK1GszgaLesYmWVXftAylKx+iHPllAniPen+lq 17erZ8z434Hp4w1nq5eVSDpS3A/uvs0CZKEoTw4FLYRKccT7XFuJPmjVaP7oaDFe4M 6AEDZaCz0yS7yvOdfuvC605+gO+5PlXJuI1/NPRKtR80Gv80BiuazfmQfmAFlgqI9H atwHF0ofn6/qkg5F2Oo1gTWx6bX8FhNErx2IdSgLRgMQon4AzZJI0LA1/7+RV8eR5E tgwE1tnMwLHvg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id B4CB318002E for ; Mon, 28 Apr 2025 20:27:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) 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,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from chrono.xqk7.com (chrono.xqk7.com [176.9.45.72]) (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 Apr 2025 20:27:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1745872213; bh=0ptD/Ehr7IzWmw2tndhV08nST3Nut4sbxtjY2h2qllE=; h=Message-ID:Date:MIME-Version:Subject:To:References:From: In-Reply-To:Content-Type:from:to:cc:subject:message-id; b=Es7sNNhEuLBlL56H8Wo1Ni9yVbMW6yYemK7+hQZMzIbwGNY6WaQBI/CYls27orCyR 25WzPkz6cgMaYZWys4lg31ZftXbFHskCdGREQA6gZHtng6YUacG4Ql/R1mj0/gq7Zj TBk09HXMgqEg9iRV8jtNBBBlCGZRDHERHogjWujDQArfWgMC5QNvOpS0DgQta1Mw1n aFg9G8SWhBQctIZVtRaVst+LtgYUrdK5GUp9JAURnfhfUYiWVYp7aYIRx8KRSkjjsy FKi4NTFSUXQjdphvBrwC7OF4EMv3cPpwCqWwdqvgDKKXNQm6iXmjE1Ab1Y6zvF8Uz6 m2qHGTA6xePeg== Message-ID: Date: Mon, 28 Apr 2025 22:30:11 +0200 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 Subject: Re: [PHP-DEV] [RFC] Throwable Hierarchy Policy for Extensions To: Larry Garfield , php internals References: <8c35314a-e307-4018-8685-39d7a7923cbe@bastelstu.be> <4de85c52-9c04-4e66-9654-af1a377015e1@app.fastmail.com> Content-Language: en-US In-Reply-To: <4de85c52-9c04-4e66-9654-af1a377015e1@app.fastmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit From: tim@bastelstu.be (=?UTF-8?Q?Tim_D=C3=BCsterhus?=) Hi On 4/28/25 22:04, Larry Garfield wrote: > Holy cow, thank you for this bit. The inability to tell what went wrong programmatically without string parsing the exception message is one of my biggest pet peeves in current exceptions. Anything particular from the standard library? It might be possible to improve this for existing extensions without creating an entirely new hierarchy and without an RFC. > * Should the property be specified as public/readonly? Should it be conventional to have accessor methods? (IMO, property FTW, no need for a method. I already do this in all my exceptions.) I would not specify this and let authors make a choice here to determine what is appropriate. The URI RFC has `public readonly array $errors;` and I think that is appropriate in that case, but in other situations, a method might be more appropriate. > * "Non-base exceptions MAY define additional properties to provide additional metadata about the nature of the error." I am tempted to strengthen that to SHOULD, to help drive the point home. Maybe use a SHOULD, and at the end add "unless the nature and details of the error is fully defined by the exceptions' type." I would not want to encourage authors to add additional properties “just in case” they might be useful by using a SHOULD phrasing. I also expect this to be something that can be resolved by simple agreement during the RFC discussion or review of the implementation. I historically also had almost no cases where additional properties on an exception provided value for *programmatic consumption*. Most of the cases could be decided by class name alone and the message was sufficient to provide additional details for the human reader in the application logs (e.g. the exact nature of a DNS resolution error). Keep in mind that additional properties cannot be handled in a generic fashion, so they are useful for programmatic consumption when catching a specific exception class only. > * Would allowing an extension-tagging interface instead of a base class be an option? It still allows for catching "anything thrown by this extension", which I presume is the goal. If not, why? See the “Choice of Base Exception” section in https://github.com/php/php-src/pull/9220. Best regards Tim Düsterhus