Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127256 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 A4FF01A00BC for ; Wed, 30 Apr 2025 18:53:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1746039077; bh=xmUF/s/BjIw1dkEjw8MHEsfRuyzw5JI8hQ0b223FrhI=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=mIoLnzew9g2u0j3Gndqnj+QpV05iYwzZ+TkpmBdYGXiI9hxKEVXU02k6W/WdR97jF n9UCQNYIbiPGEs7Ly5ickdjLBSsC1hIBdtK1r1URMXdno7Sd7+TaPwFlUKUIzJGyDg JSP72lljyf3MpOYptE7m4ELmMDfd4NUqAEda20KmZJhArmzD9GaPa4p+eR+ot7iPO0 b0vCZYm0sewJku1Lcjh0p7xqRx48iapB12vGAqtGzWfMEiNSCJ9pBjKqenonT/6l/U yXWjgDMzlbGGjGrQldSHHOeG2hQewVH/Qy6z3THiFtvNWhocfGdB1KHCIEmxmjmAzr V0INLXJ2+pWsw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 8325718006C for ; Wed, 30 Apr 2025 18:51:16 +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=-2.1 required=5.0 tests=BAYES_00,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 ; Wed, 30 Apr 2025 18:51:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1746039211; bh=5oIRcpvqrbBllbWlcA7Hy7fMQjAjP3QsJwtQUEjhsCY=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type:from:to:cc:subject:message-id; b=KRt0Py26h/Ad26KzUCUmrzCoNplj6XoRcv0guz4Ry5OfOHNnNA8rh8WZqyhaGlg1p 63sBcvAAvB+thIKKzQl27j7CQ85Y6GQWnAQhZYbaE54efnnG21eXNr7+sdHyES3pod WaJu7fkw/tcdAUXC/hLBV4oWkNH1eL1+xWV4FtYNRhVuUrxIpEPFvOuujiId10H/zu dGrAvX31jcfMyzOP39Hp8dFmGkfkv9dcxCXTcrdZ0x8HMtRHQftg2rnX+6DDZ6FPm8 4bmI8/T+uXsG+vY99pVxM9CAnHBybSZPAz+6/GkmdZZHdn/lRce8RKOv4EPTwrftp8 JqLdgxG0Hp7Xw== Message-ID: Date: Wed, 30 Apr 2025 20:53:30 +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: Derick Rethans Cc: PHP internals , "Gina P. Banyard" References: <4233b00a-7593-e70d-f235-da650cd7bac6@php.net> Content-Language: en-US In-Reply-To: <4233b00a-7593-e70d-f235-da650cd7bac6@php.net> 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/30/25 13:18, Derick Rethans wrote: > - Exceptions MUST NOT be ``final``. > > Could the RFC explain why not? I'm not sure if this is useful to add to the RFC itself as a “only extra explanation” and since the discussion is an equally official resource: The reason is to allow flexible extensions of the exception hierarchy, e.g. when adding a more specific type of exception to provide further context to some parent exception that just identifies some “concept”. A HTTP request can fail (HttpRequestFailedExceptions) for different reasons, e.g. due to a connection failure (ConnectionFailedException) or due to a server error (ServerErrorException). Now we might also want to clarify why the connection failed. It could be a timeout (ConnectionTimeoutException) or DNS resolution error (DnsResolutionFailedException). This already requires several of the exceptions not to be final to allow extending them. Making the leaf exceptions final would not bring any value and just cause additional churn when realizing that having more child exceptions would be helpful to the user. Also some extension might intentionally want to allow subclassing for some classes. When subclassing a class it also makes sense being able to subclass the corresponding exceptions. I have made it legal to throw “unowned” exceptions when subclassing something in: https://github.com/php/policies/pull/17/commits/1a125dabea93b4c919677065651c4fdea1b035e3 > - The name of the extension SHOULD NOT be used as a prefix or suffix of > the unqualified class name of additional exceptions. > > Could you add an example of how to do it instead (or a "not this" "but > that" example)? I've expanded on this paragraph and added an example in: https://github.com/php/policies/pull/17/commits/c0e8891fc9a7a459a26a990b33108bfbd5ae3311 Basically the intention is to avoid class names “oddly specific” names that just concatenate some random words. Ideally the class name would be a succinct English phrase that matches what you would communicate them to a co-worker. I would say “The HTTP request failed”, but not “The HTTP request that we perform using the network request library called curl failed”. Or I would say “The timezone is invalid” rather than “The timezone, which relates to the concept called ‘date’ (and not any other use of the term timezone) is invalid”. How exactly that works in practice greatly depends on the extension, that's why it's just a SHOULD (NOT). I trust that folks make good choices when they have a reminder to make a good choice. > - Any two exceptions with different causes MUST be identifiable either > by a unique exception class name, a stable ``$code``, or a > class-specific additional property suitable for programmatic > consumption (e.g. an enum). > > I would probably not even allow the stable ``$code`` in here, as I have > seen from experience people don't really check for them. My goal here is to avoid making exception messages part of the backwards compatibility promise. Whether or not the `$code` is useful in practice will be something that folks can figure out when writing an RFC. It probably greatly depends on the type of extension what makes sense. Perhaps it would also make sense to officially widen the code from `int` to `int|string|UnitEnum` to avoid the PDO gotcha. Since `__construct()` does not participate in LSP checks and since `getCode()` is already final, this seems safe to me. Best regards Tim Düsterhus