Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126464 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 qa.php.net (Postfix) with ESMTPS id 817311A00BC for ; Thu, 20 Feb 2025 15:42:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1740065991; bh=M0hcYxFh8QEulSjIebAWDPW924xx75tILvMTPJsfzCE=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=SqOLFgjp5MMZDxKRGkVn98hLHEvnJ1xdToVHFNHNa9+z2tN4O+1Io0u2cMzXnCsWX 7Y555+PUZe/vCLenO52M2LbLu+leNE7+f0ze1MQXKrKE2QBSrjuJ6HiaFWfbIkW7iK KcO/jPF3b1URDHzkPACLULQBm2bzeI1KVSbpNeo6rOATvtTgcmFs4NSdbZDnG0J3ie 2A6hUhhaWD8Kto9P2DlHAfq6aDRUcXh+qsgJasiZtmfZpkyw0knb2rgJOLuu5M3vd+ K0Qm4jqteJFeGs6xfz7rSp+p9zzYHwsQH+MOfQ1EgMhhmHmOpDOMJEIPJO9LCXNZfv 3uPRvclqKV+eQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 199FB18007E for ; Thu, 20 Feb 2025 15:39:50 +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.6 required=5.0 tests=BAYES_50,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: No 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 ; Thu, 20 Feb 2025 15:39:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1740066148; bh=LcUCnbSkVVuw3k/u1Z0nluSaKlCQkZY9A+1qu135ox0=; h=MIME-Version:Date:From:To:Cc:Subject:In-Reply-To:References: Message-ID:Content-Type:from:to:cc:subject:message-id; b=FbTO/DNAnNAVLiCODnAC0iIgZQQiSwyl9OAg1CsJXAF9t1S2/PEfUSFDuG7qTgOUW u9RiczBPFfaIndpW0G9AkMrWieXNMXPPNbpX5qne432fCAkdpR3I9snwBQZJkXS0+R 1VaUv5OhUh/4aGXpUN/NqGPfy3/kwPlAjxiTiWkQE2qy7GXesO1uX8D4wRNP4mG5H6 fhMfsC1pZPBAwltLsdcrYUsfyCTMd9mdToRPspnQU4sm9FwRGeXxG8wjWYRqB4+Pn2 UnUXQq+tayUTXRsWSLztwmqoZzr0MnhYxLTDPvJgyAN/IggS8hylkL1ACqZowllrqF yj6jKPIYOhr7A== Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 Date: Thu, 20 Feb 2025 16:42:28 +0100 To: Bilge Cc: internals@lists.php.net Subject: Re: [PHP-DEV] RFC: Marking return values as important (#[\NoDiscard]) In-Reply-To: References: Message-ID: 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 Apologies for the delay in getting back to you. Volker was out of office and I try to coordinate the replies with him to not misrepresent his opinion. Am 2025-02-12 14:17, schrieb Bilge: > Apologies if this has already been brought up; I haven't read the > entire thread, but isn't the entire premise of this RFC based on a > falsehood? We do not believe so. >> This kind of “partial success” can only be reliably communicated by >> means of a return value > > Exceptions are objects, so you can attach whatever additional > information you wish to that object. > > Perhaps the word "reliably" is doing a lot of heavy lifting in that > sentence, but if you would refute me (which presumably you will), then > I think this needs to be explained in better detail in the RFC, because > it looks to me that exploiting object properties is just as viable as > returning something, and probably preferred, since this solves your > problem of the user not handling the failure. Perhaps one can find a better word than “reliably” there, nevertheless: We disagree that throwing an Exception is an appropriate solution to communicate partial success. While it certainly would ensure that developers can't forget to handle the (partial) failure case, it would also be a very non-idiomatic use of Exceptions. Instead of being able to check `->getMessage()` or `->getCode()` to find out the cause, which is automatically supported by generic Exception-handling mechanisms as provided by every framework, one needs to specifically call a `->getResults()` methods to find out the individual results. And when it's a generic function where depending on the type of item processed, one is also interested in the “return value” of the successful cases, instead of the binary success/failure option, it would become very unwieldy, requiring the use of a single-statement try-block to handle both the “all successful” and the “at least one failure” case, ending up in a “return value with extra steps” situation. try { $results = bulk_process($items); /* All successful. */ } catch (BulkProcessingFailures $e) { $results = $e->getResults(); /* At least one failed. */ } foreach ($results as $item => $result) { if ($result instanceof SuccessResult) { echo "Created item ", $item, " with ID: ", $result->getId(), PHP_EOL; } else { echo "Failed to create item ", $item, PHP_EOL; } } Best regards Tim Düsterhus