Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122326 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 63410 invoked from network); 7 Feb 2024 11:58:13 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 7 Feb 2024 11:58:13 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1707307145; bh=N2PuDtuyF+iy+0EhcsJtZvrcLK11PsTvhtNFNiGPofs=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=H40nXqh7cRU2WrOpJ3NuqnAccsi5yaCWL/JM92b7WOPMX93EJQTxdxwzGeEXDw4vB 3CTR3rsF0KrsdTD8g0Zd5so1zmBlxKdyuJfRUhGyL5S4Pc+nVL0eO/gs4s+OeiewxY swFOnmBkaDbzpvLTT590yiHtGtHm1uGvIC+7Cda/VhS6STVfB/xjAck3B+mazMXbTv bbM8xtxGCIJ0VzPsY6TSQgtjsCcPYHpAqrWT/lczfnIJry/y5WXN1RkI2eN+g42Onz 6ZMvknf737TCAEOcMW1j3mg6ov8phNlKcTFCEQo0tCrWmaA4a66Q7nPSIhiwu0uYEC SWq94B3vpskPA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 05DED18006C for ; Wed, 7 Feb 2024 03:59:03 -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_FROM,FREEMAIL_REPLY,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: Received: from mail-oo1-f49.google.com (mail-oo1-f49.google.com [209.85.161.49]) (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 03:59:02 -0800 (PST) Received: by mail-oo1-f49.google.com with SMTP id 006d021491bc7-5957ede4deaso288986eaf.1 for ; Wed, 07 Feb 2024 03:58:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707307089; x=1707911889; darn=lists.php.net; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=CgLe1eSY9qpkWrbzfRhFFbOQgKQO1sIztiuMfrBkgOU=; b=Qor5pfWapzMjO+8ohpNrC1cujxrfzY+noRybLMwU3yqetDAsKr2mxUO07OGeqsQ1YI tgiMC83Qvz0pTJneVyptzsJloYFH9TkXEVxgfJHm7vJ4qrdCIvWAWr/Vhl+rxL64YdYI iSb2AERMhJLDaSg0tcvu93vg1Z2JuJ4coACUuocsmIxLb/m7o8BSAPD8lfIBUOEYDEPs H154EnRZaynVNn8g6SHs8t3lMLHuTntIASCC+1vfXx8dT+Z/ddtNE9F7NSdwbRu9GLM4 gGmL2nark23MQNAa/S+3gEcF0F07GzHPj7CBl1IVare/WOQhpU9GQ+tsoobz3YAtqaQp nWEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707307089; x=1707911889; h=content-transfer-encoding:cc: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=CgLe1eSY9qpkWrbzfRhFFbOQgKQO1sIztiuMfrBkgOU=; b=nznBCnDblSffI/6YI8u6HKVQ7Mm8pZfO1jFyg+DVdrbyh3ZOhSS750K4rRvzRZrQOR QVTbd68/BvkJfcwDkOQnAJzZHAnL7AdcZAIW6KZkl49M+HPutsXIE7QLvLv+IIp+SwVP FKrL+ZYlSRN0vdQDzZAAa6PnYjY6iAL+BuEFT2jpok+lUPtKv6Ipv3NRc0dlb8UbFqKG BRQpH64J0kEMLlVGQweLPnq11T8TXZFJcbBmdl3JATdp2Lb/A6ZVSaosSydfPFaS7jYP VJ0e3u49/+3s0J7tRWwQyzCMJeedqegvIQuCXpsHGd5nwR55kFP0qkXpJY90Fw9HCHMn mYTQ== X-Gm-Message-State: AOJu0Ywv+6oy8Y+z9+ebJ6kYw96nuiuu9xeJ+FNhnp3BB/NjMUQwbZ9a WJXowGrX/GWSDzMHuaPoeyIzmWJXe4ZoDya/wdieqvvi1QXuY6lNbjM9VUDezzNq4ej0gIMUXBQ 0/wXC5Do076fbqvaOxnuBMtZKjyw= X-Google-Smtp-Source: AGHT+IGsOV+4vaggtlNwwLZgirYc+ddhC1MBgQcWp06So8ayjeoHc9qTEv93mEvvRqO+PmGY6JrrEAeRgxoUisjLByo= X-Received: by 2002:a4a:d285:0:b0:59c:9099:6488 with SMTP id h5-20020a4ad285000000b0059c90996488mr5712122oos.5.1707307089145; Wed, 07 Feb 2024 03:58: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: Date: Wed, 7 Feb 2024 12:57:57 +0100 Message-ID: To: =?UTF-8?B?0JPRgNC40LPQvtGA0LjQuSBTZW5pb3IgUEhQIC8g0KDQsNC30YDQsNCx0L7RgtGH0LjQuiBXZWI=?= <6562680@gmail.com> Cc: internals@lists.php.net 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: landers.robert@gmail.com (Robert Landers) On Wed, Feb 7, 2024 at 11:27=E2=80=AFAM =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 <6562680@gmail.com> wrote: > > 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 re= turned an array with two results. > > The trouble was you have to refactor all places you used your function do= esn'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 - yo= u have to implement that (refactoring the places where null is inapplicable= ), but error collection itself won't change existing code then, it works li= ke 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 no= t >> > > 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 err= or, and >> > > yes, write return class/enum to extend/refactor it later) >> > > (and yes, if old code did not support returning null/null-object bef= ore - >> > > 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 s= ave >> > > 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 t= he >> > > second method, then debug the second method. >> > > >> > > So what's in rest? Arrays collection of warnings and errors. Changin= g >> > > 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 func= tion or >> > > in place I call the function. I want to share this experience, and i= magined >> > > 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 t= o 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 t= hem >> > > recommend: >> > > 1. Use exceptions, don't make anything fresh >> > > 2. Do validation at the script start to reduce the count of errors l= ater >> > > >> > > I've just encountered cases where bugs come from within - once you >> > > integrate a really bad external system with its own checks, which ar= e >> > > described in hundreds of documents, I'm sure you'll encounter new bu= gs 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 beli= eve in >> > > "watching for". >> > I think there's a subtle but important difference here between what yo= u'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 two= possible ways to do that, both of them bad: Unchecked exceptions and globa= ls. >> > >> > What I described, based on the syntax you offered, is checked exceptio= ns, which necessarily means changing the function signature. Error handlin= g is part of the contract of a function. If its error handling changes, it= *should* have a signature change to indicate that. (That unchecked except= ions do not do that is the problem with unchecked exceptions.) So if "no c= hanges 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 genera= lized version of `json_last_error()` and similar functions. The problem th= ere is that such an API design is generally considered very poor practice o= utside of C, because it's all necessarily based on globals and "hope you re= membered to check the thing that no one told you to check and is not even s= lightly obvious to check". That is not something I would want better suppo= rt 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. Ther= e'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 don't think anything the langu= age 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 >> > > > -- > +375 (29) 676-48-68 / 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 Please don't top-post your replies. It's very rude. If it's just syntax around arrays, it's something that doesn't require much (if any refactoring) $result =3D getResult(); could be seen by PHP as the same as [$result] =3D getResult(); Allowing you to implement things as fast or as slow as you wanted to, or ignore errors completely. Robert Landers Software Engineer Utrecht NL