Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122318 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 16797 invoked from network); 6 Feb 2024 20:22:14 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 6 Feb 2024 20:22:14 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1707250986; bh=qp04KSpsbnZw9vcCjOXcA59kl8ftycR8nq/13l/9Xog=; h=In-Reply-To:References:Date:From:To:Subject:From; b=LoGpWNE8r6Qn+7KlXE5j1oPjrc3ardatVKQ9qBqJlu+sUkqfl9fQixHnEM7DqOwD6 qOVtQ0au0LhfUPGSMvSEeisIrMQ0CczwexgZ9pkAJXcYGRb+fxBi1WmQ2bsk9Ct7XX 0sZ3YdjDX/gRDwvhJJaB7s5EzejxQ8sjLYgcVZtGSt/lBS+aTmMeaRYSH5cLv8RANx bObJNmKyHsDOQNIVLhxNCDxaSHlCHpzjDK3L2sS9b+uNDxHEHRqiLbYEbR2erdDw75 SjBU5L2UTfWGi7ShspTOHSjqJBcNsvDgaGy5ILx0mdpHLn8CZ80HUS42huhezir9gT D27gruzoEeD9Q== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 4DFA518005A for ; Tue, 6 Feb 2024 12:23:06 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,BODY_8BITS, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING, RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 6 Feb 2024 12:23:05 -0800 (PST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 500445C0111 for ; Tue, 6 Feb 2024 15:22:13 -0500 (EST) Received: from imap50 ([10.202.2.100]) by compute1.internal (MEProxy); Tue, 06 Feb 2024 15:22:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to; s=fm3; t=1707250933; x=1707337333; bh=9aHJ93SfXxmO8u44/D587 TuyW7p96eGXPSu8pAhp1FI=; b=KgmpkHvcjBiDYhM95eUPDhCZa4qFH6eEtOOPO Arj9dFTDK9lgolurnsXhmYRXT6eGhrCrlLkSp3RaSYYrE+BAYX4u6mtisGxdpWHd AanS7cpX+aLvIIAfFZntnk6O7tuGfeB7NUxy/XTcojjCKHHkUiCDKHhA+E+avAbi 3j0eglzlOgdzPmmTDf3mlfDknQVBPDjAGHd6Jp0tWnyTiqQ6NfQcgADlQFtaLr95 WQk/p3ZLHd3w1y7AHvCbzh0BJwOMTgjJQc07ttjjzLfUCrnrGnYg/eCmjSbh61ty UT4xrw5oIrvDGJgxFcZrAliQdJrHZJZIFuD0mNF/36n8etDCg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1707250933; x= 1707337333; bh=9aHJ93SfXxmO8u44/D587TuyW7p96eGXPSu8pAhp1FI=; b=N 2l20yw0bdgyWYjb/TYhteFhJj0geJrVtXFhlcbz0rLe09Kmou8umA/wxv5EXTxSi 5apCfZz4Lgv72feZI77ghE254ruqudvrurenh2UTeoKOQONUqARNRJjZdMSsUmf2 H1D4w6QgmI2hz3XdOqP9D/QDxTZdBpcms1pDWoO8BC45m3RNngKR9F/gXZ1yZU5K 4TuYJNXY08U6DonFpqTqXvalXm67QXO0GGEepVqtiSgcMGgd/Mk1dZOxpz4SbvWl XvbnFRbR5ukBLxl/Klj0gImI4JWlhSAvBVTzY86842ncp+4fjMXwJ3GjIpQwwOlp lklOWSwsYAMqY7n/LlO/w== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrtddtgddutdeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgfgsehtqhertderreejnecuhfhrohhmpedfnfgr rhhrhicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtg homheqnecuggftrfgrthhtvghrnhephfektdffgffhkeeiudehvdehfefgfeehuefgvdel teetkeetgfetjeeiledtleeknecuffhomhgrihhnpehgihhthhhusgdrtghomhenucevlh hushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehlrghrrhihsehg rghrfhhivghlughtvggthhdrtghomh X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 02C031700093; Tue, 6 Feb 2024 15:22:12 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.11.0-alpha0-144-ge5821d614e-fm-20240125.002-ge5821d61 MIME-Version: 1.0 Message-ID: <3db4fbe0-22f4-44e2-a1a6-6cd85287df56@app.fastmail.com> In-Reply-To: References: <742f202d-7990-4f51-b903-7a15e3fd33c2@app.fastmail.com> Date: Tue, 06 Feb 2024 20:21:52 +0000 To: "php internals" Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Feature request: https://github.com/php/php-src/issues/13301 From: larry@garfieldtech.com ("Larry Garfield") On Tue, Feb 6, 2024, at 7:56 PM, =D0=93=D1=80=D0=B8=D0=B3=D0=BE=D1=80=D0= =B8=D0=B9 Senior PHP / =D0=A0=D0=B0=D0=B7=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D1= =87=D0=B8=D0=BA Web wrote: > Thanks Larry, I will read both articles next weekend. > > Am not even talking about changing `throw` to `raise`. > > Am talking only about: > - production ready code > - that should be able to refactor with error collectors (that was not > implemented years ago) > - without touching return types > - without touching input arguments of existing code > - without possible code fall after throw exception: you have to try/ca= tch > all places you use that function (sometimes you predict possible error= , and > yes, write return class/enum to extend/refactor it later) > (and yes, if old code did not support returning null/null-object befor= e - > you have to refactor return types then) > > While working with queues you have a list of tasks > - then you reduce it to smaller with reducer (unique/filter/merge) > - then do some queries > - then walk initial data using reduced results: copying reports to save > errors/warnings to each task separately > > It cannot be solved with exceptions. In addition, large arrays throw > exceptions that cause timeloss. It's definitely not a tool for. > Also your method could return many errors (today - only one > error/exception), and you need to write a second method, then call the > second method, then debug the second method. > > So what's in rest? Arrays collection of warnings and errors. Changing > return types or passing second-return by reference. > > [ Enum case ~ DTO output ] covers newly written code. Old code is > uncovered. You have to rewrite a full tree, that's why some trick is > necessary. > > I did it my way with an error bag stack. I enable it inside the functi= on or > in place I call the function. I want to share this experience, and ima= gined > it would be better for all users. It could be done without 2 classes, = 10 > functions and work with push/pop/current (closer to ob_start/ob_get_cl= ean > story). > I guess it could be implemented if `raise` world will put any data to = the > current error bag in the stack. Exactly if the current error bag is pr= esent > (declared manually like you can declare() strict types or ticks for so= me > scope). > > I agree that there's more mandatory problems to solve that I didn't ev= en > know about. > I tried to talk about error handling with a few developers, all of them > recommend: > 1. Use exceptions, don't make anything fresh > 2. Do validation at the script start to reduce the count of errors lat= er > > I've just encountered cases where bugs come from within - once you > integrate a really bad external system with its own checks, which are > described in hundreds of documents, I'm sure you'll encounter new bugs= once > the "working" code is released to production. And then you will need to > quickly and easily reorganize it. > > And you can't. > And you will be sad. > And, "PHP moves differently" is a completely wrong principle, I believ= e in > "watching for". I think there's a subtle but important difference here between what you'= re describing as the problem and what you implied the solution was (whic= h I then ran with). What you're talking about is trying to change the error handling model o= f existing code without changing function signatures. There are only tw= o possible ways to do that, both of them bad: Unchecked exceptions and g= lobals. What I described, based on the syntax you offered, is checked exceptions= , which necessarily means changing the function signature. Error handli= ng is part of the contract of a function. If its error handling changes= , it *should* have a signature change to indicate that. (That unchecked= exceptions do not do that is the problem with unchecked exceptions.) S= o if "no changes to existing code" is the goal, checked exceptions as I = describe them are not the answer you are looking for. It seems from your latest message that you're describing more a generali= zed version of `json_last_error()` and similar functions. The problem t= here is that such an API design is generally considered very poor practi= ce outside of C, because it's all necessarily based on globals and "hope= you remembered to check the thing that no one told you to check and is = not even slightly obvious to check". That is not something I would want= better support for in the language at all. There's probably cleaner wa= ys to emulate it in user-space, but that is for a particular application= to sort out. There's definitely cleaner monadic solutions (which I've = written before and are quite neat) using a writer/logger monad, but that= again doesn't meet your "don't change existing code" requirement. I do= n't think anything the language can do will meet that requirement and be= a good design. --Larry Garfield