Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122325 Return-Path: <6562680@gmail.com> Delivered-To: mailing list internals@lists.php.net Received: (qmail 58900 invoked from network); 7 Feb 2024 10:27:11 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 7 Feb 2024 10:27:11 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1707301683; bh=NQ8N92UEfdw7dotKU/20ggLQ9PALXXWETAp2xeM8IuM=; h=References:In-Reply-To:From:Date:Subject:To:From; b=j2b7wgqQrmyRrEuYoTJqNZuEejyfxbLXf7vSX8pxsVzFUCbfeQcM07QyXQJU46D8I PH/M4wXQrSZgJXNjVXp2491b6InLAcvIMTzIVAsG7phFGtY9I3gfcbjh56eLE/ul0Y mXVEjToTMMeKYROoXxbkJLW9BnBS5cM1ddV1GhM3KIpM5vQ1GCDbzbm+28G1dD9XMc GFCYalT6FZ5iRnrIqAjbo+Y50bp+jNtkLUPR5qtAGCZF6Y7dvoqSG0RqNIFECePcd/ Lv0vLI++GDLJvrn/EUsMS6sy00QjKg3G9e0vTgIf2/Q3w9Csl/B1i9+K5cIOfidnsE +wxq+wlupQzMQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D7947180069 for ; Wed, 7 Feb 2024 02:28:02 -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=-0.4 required=5.0 tests=BAYES_00,BODY_8BITS, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS, FREEMAIL_ENVFROM_END_DIGIT,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.0 X-Spam-Virus: No X-Envelope-From: <6562680@gmail.com> Received: from mail-oo1-f45.google.com (mail-oo1-f45.google.com [209.85.161.45]) (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, 7 Feb 2024 02:28:02 -0800 (PST) Received: by mail-oo1-f45.google.com with SMTP id 006d021491bc7-59a9a737273so116838eaf.1 for ; Wed, 07 Feb 2024 02:27:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707301629; x=1707906429; darn=lists.php.net; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=rlm/Jv6/WmgCQpdsNF9M3AUWGxzrwHDnhZqPKqk0B+4=; b=Nmf3xYsugjNJdxZy9fMhHTPkp4vCO9QztzFTdDdN8vGo2/CgXt7qvMY37velTzrHLb p+PbxgRmBTQ9Bhnb7MOANbJ/3trQnAF6rBtBxWIAUiWPpB3LtDXtgnLiiFolCfw4Tg/P sNIJiopENkuFWkvNU22FOnycukLfo6vh+U+KsbregyA6dY2/dldxp94oozJG05sgInIa 3x1dcTbgAFFB+kzwmHqYYYJixWPW6R7+0E7cYVxeIoFV7jh+QqVCPYivO0Ea01TaVr8Y IBziZVzgjptfeSERpuSDY8GUbiI/Vf5deVT+//6OuHb5vnjqx8Rg2aAMNo+vwtDGMofa BbAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707301629; x=1707906429; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=rlm/Jv6/WmgCQpdsNF9M3AUWGxzrwHDnhZqPKqk0B+4=; b=QYbb6ExiAfxKEyWKbibjnjqj9GuckjOpksi28y6pBVdmNQmdcEYdDP4KREOjUvaJX4 oTKuKvui/3pH9+GmmNZ9J+wDIVvfsnuUrih72CZ5Oh0j/cyP1cMA7TImTON9/SBzuCuq M5M4vavMbeWitlEQbeHbHtWSW5TG/9f7q5SFYxCkVYKqKQEdpLQDhjnX95a9JPId5edP BRRRKCXKs9k1I2kFiwEI4uPDCzT7hswHHcX7aHCDlcIrjy6LuYp4IeXsWUfuvzCXacIm h1SFlXk/DFH12I1xb6GNPdXnADvMolgFgQ1gTkVsx8Jpy4Ixx9J1Fr7dDVYGz7PGAUoG 6ofQ== X-Forwarded-Encrypted: i=1; AJvYcCWv6AcPajaEM9cT5nGnE85G4KB33oOGmyVzChZ3lUasnsPi4bcS0IS00CydW5JrJdavP7Ww+u3nvY9k8PrL32/s/aoJeHy9FQ== X-Gm-Message-State: AOJu0YxHKqOvQXN5VJ7vqw2D0GNBzd+hcoy9KX6VKILzbfpDeibDVdxL NQIwwx1x4/hrirVNIXmDenrmpOstSB1hlqo1V6w6geeNikmQWntUg9OBXwYsWmKiPjvV27A9WMs +B/UAmHEzjqCjynBfLoigbDfvReQ= X-Google-Smtp-Source: AGHT+IF1BNZVSTKj1ety31mBNPo+qEQCSyqlFv+OTTOmVZ109P0ZO11l7kAGEtdfTiy5M/kpVh/TMlhs1mKK6jWeASw= X-Received: by 2002:a4a:b445:0:b0:59c:e5cd:5b14 with SMTP id h5-20020a4ab445000000b0059ce5cd5b14mr4638357ooo.0.1707301629058; Wed, 07 Feb 2024 02:27:09 -0800 (PST) MIME-Version: 1.0 References: <742f202d-7990-4f51-b903-7a15e3fd33c2@app.fastmail.com> <3db4fbe0-22f4-44e2-a1a6-6cd85287df56@app.fastmail.com> In-Reply-To: =?UTF-8?B?Yg==?= <6562680@gmail.com> Date: Wed, 7 Feb 2024 13:26:32 +0300 Message-ID: To: Robert Landers , internals@lists.php.net Content-Type: multipart/alternative; boundary="0000000000001fe4440610c82317" Subject: Re: [PHP-DEV] Feature request: https://github.com/php/php-src/issues/13301 From: 6562680@gmail.com (=?UTF-8?B?0JPRgNC40LPQvtGA0LjQuSBTZW5pb3IgUEhQIC8g0KDQsNC30YDQsNCx0L7RgtGH0LjQuiBXZQ==?==?UTF-8?B?Yg==?=) --0000000000001fe4440610c82317 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Yes, that was the second build of the error bag I presented in the github ticket. First one was a Trait that added an error bag as property in class and returned an array with two results. The trouble was you have to refactor all places you used your function doesn't matter, want you or not. And the last build just collects errors to the global stack of error bags allowing you to stay untouched by the existing code. Of course, if code should start to return null/null-object as result - you have to implement that (refactoring the places where null is inapplicable), but error collection itself won't change existing code then, it works like an observer pattern now. =D1=81=D1=80, 7 =D1=84=D0=B5=D0=B2=D1=80. 2024=E2=80=AF=D0=B3. =D0=B2 13:21= , Robert Landers : > On Tue, Feb 6, 2024 at 9:22=E2=80=AFPM Larry Garfield > wrote: > > > > 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/catch > > > 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 > before - > > > 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 sa= ve > > > 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 th= e > > > 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 > function or > > > in place I call the function. I want to share this experience, and > imagined > > > 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_clean > > > 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 > present > > > (declared manually like you can declare() strict types or ticks for > some > > > scope). > > > > > > I agree that there's more mandatory problems to solve that I didn't > even > > > know about. > > > I tried to talk about error handling with a few developers, all of th= em > > > recommend: > > > 1. Use exceptions, don't make anything fresh > > > 2. Do validation at the script start to reduce the count of errors > later > > > > > > 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 bug= s > 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 > believe 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 > (which I then ran with). > > > > What you're talking about is trying to change the error handling model > of existing code without changing function signatures. There are only tw= o > possible ways to do that, both of them bad: Unchecked exceptions and > globals. > > > > What I described, based on the syntax you offered, is checked > exceptions, which necessarily means changing the function signature. Err= or > handling 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.) So 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 > generalized version of `json_last_error()` and similar functions. The > problem there is that such an API design is generally considered very poo= r > practice 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 wa= nt > better support for in the language at all. There's probably cleaner ways > 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 writt= en > before and are quite neat) using a writer/logger monad, but that again > doesn't meet your "don't change existing code" requirement. I don't thin= k > anything the language can do will meet that requirement and be a good > design. > > > > --Larry Garfield > > > > -- > > PHP Internals - PHP Runtime Development Mailing List > > To unsubscribe, visit: https://www.php.net/unsub.php > > > > Oh wow, this conversation got really interesting while I was asleep :D > > I think this could actually be interesting in a > semi-backwards-compatible way, by just adding some syntax sugar: > > function getResult(): ?Result, ?ResultError { > if($error) return null, $error; > } > > instead of, but this would still work when destructuring: > > function getResult(): array { > if($error) return [null, $error); > } > > This would still work (the "backwards compatible" part): > > [$result, $error] =3D getResult(); > > or this: > > $result, $error =3D getResult(); > > Essentially, return types with a comma are just a "strongly typed > array" and a comma on the left-hand side of assignment is just a > destructure. > > Robert Landers > Software Engineer > Utrecht NL > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > > --=20 +375 (29) 676-48-68 <+375296764868> / Mobile - =D0=BF=D1=80=D0=B5=D0=B4=D0= =BF=D0=BE=D1=87=D0=B8=D1=82=D0=B0=D0=B5=D0=BC=D1=8B=D0=B9 =D1=81=D0=BF=D0= =BE=D1=81=D0=BE=D0=B1 =D1=81=D0=B2=D1=8F=D0=B7=D0=B8 https://t.me/gzhegow / https://t.me/%2B375296764868 / Telegram 6562680@gmail.com --0000000000001fe4440610c82317--