Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122300 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 81413 invoked from network); 6 Feb 2024 15:30:39 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 6 Feb 2024 15:30:39 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1707233482; bh=vkpCMA7+RzGJJmrOCfgAElrSNYP8i55C0OtYxvHLojE=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=XxQq6GxobzYXN9Sbr98U6Gz5faXtSeAxVmJm7ZI8dk7qsGJm5yWWkXhCR2JoUO22d VtwPVIfSxe98PNhMOxHLeJCvGOMHFnT2HGtdZZ/j0+XlYpQ/sx7Vqtr8eDpBzVbOr6 qWQI1lxuQflLzocFGMAuvoKJ3YZtwwUsol/wbJiuEAu3ujhFaLDYRbSPuR+XRt4nJh nyqoFM3w1XKk3CAUKQxqdCHv8obkCrathJ79xFfcmCpy+L730f12agNMTCEjrX/WU6 1H1bx0rihtORNOcCn0+05ET877Bf804M87qcQiTFqef8DHzx318BAFkqJ4/+TEf8kL 5oIgar4R5MJMA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id BED15180064 for ; Tue, 6 Feb 2024 07:31:21 -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-f50.google.com (mail-oo1-f50.google.com [209.85.161.50]) (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 ; Tue, 6 Feb 2024 07:31:21 -0800 (PST) Received: by mail-oo1-f50.google.com with SMTP id 006d021491bc7-59a7682486aso2198801eaf.2 for ; Tue, 06 Feb 2024 07:30:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707233428; x=1707838228; 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=vkpCMA7+RzGJJmrOCfgAElrSNYP8i55C0OtYxvHLojE=; b=WWEbH2LYGEU+/EF4B1/sGj6auKBOK9ln3xUeLwwbBvZ1kuD7sPdf/IQI/mxg/Woo7z GIAniG+jr/zXi3psZ1VSIY9c4zZ7aAA96fdF/gozUIuEBdTEZERR44+kKqav8JAZ3D20 tVMuqHHVurkfcZIsw0cazBqLD/fufdwZbwN1lT9F35Rc9lo20UG4/qT6a8kitaQRauFF aql9YBu4SnQFJX69Z4Tpy2rD4rGhvtlLRAG35XGOYorPi79sJ82NXZVr1tIu6ayXQwER rNGO9tLcTpx6icM8UzVfv3cJN/vJVlsfcJsjgxxhbyB73ioBp74fVdXEsj7gqP8oPbOs LTkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707233428; x=1707838228; 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=vkpCMA7+RzGJJmrOCfgAElrSNYP8i55C0OtYxvHLojE=; b=I0dhiObWSKHMRylw5KGvU9MZOR7xiJMiOlxZI6e5RvettN5Alw06nqC2Hvm972Y7Oi IIcEOFxyIiO94XR1pFEHoYP8674r3t2eyT8kotrNaEWkUctyI+iHpO8SjOWMGjU+lYba /lobiPlIUUZN23yADanjldSqq/Xf/PZcvXZ9gsKBOzTlkgWaQYeViDAHWGezhHnHmopv utGfi9kUB29AoXFk6Cal9EdYwrHb1Ysb/3MCI7a1z92mQ0RWKC5zsIxn2ogio/ZclLke EWvDdkfuBPXn1SMTx4E1jNnBBrc7QeT2Xw0cXEN+4xzRuIvMx4ZxoHOmQFhgHCd9a8lX c+yQ== X-Gm-Message-State: AOJu0Yw0rAlNgo8yJp985LqcrT6YA0xjd1lhMWA+4fAul/cSZL2LJUQF H80t39XLES0WgDH3wksvJIzzTn3OJZ+5lQNvRvG217aSZaVxa7h7ayEMP262SLC7a6LHsQHi8kY zbWkjGH4kT8+aG1oqcmwgTw90sdk= X-Google-Smtp-Source: AGHT+IH9x+IbT8JXfJTzbgV+JAnfgbZBRmC1O1wX2Hn4izSrnwELYglw/JXa2unk/YZB8iFAAkpbfS6N4wcuZGbcEX0= X-Received: by 2002:a4a:651c:0:b0:59a:96a1:dd0b with SMTP id y28-20020a4a651c000000b0059a96a1dd0bmr3100381ooc.5.1707233428482; Tue, 06 Feb 2024 07:30:28 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 6 Feb 2024 16:30:17 +0100 Message-ID: To: =?UTF-8?B?0JPRgNC40LPQvtGA0LjQuSBTZW5pb3IgUEhQIC8g0KDQsNC30YDQsNCx0L7RgtGH0LjQuiBXZWI=?= <6562680@gmail.com> Cc: Alexander Pravdin , 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 Tue, Feb 6, 2024 at 4:26=E2=80=AFPM =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: > > Short answer is yes. Glad to see that personally adapted answer. > > That's why in the relevant github issue i show how to collect ONLY if you > need. > If you initialize the error bag - it collects, if not - it skips. T > > So the `try/catch` statement outside means you initialized, also a specia= l > decorator or additional command could initiate the raise collector right = in > the function ! > > You collect only the cases you want to collect. That's the difference. > > > > Tue, Feb 6 2024 at 18:20, Alexander Pravdin : > > > On Wed, Feb 7, 2024 at 12:00=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: > > > > > > Sending you private emails made because "answer" button in Gmail sele= cts > > > only you to receive. > > > Sending you private emails that don't even read signs to me you don't > > need > > > my answers and have no benefits from reading. But you deny, dont even > > want > > > to understand. And notify all subscribers about what you don't want t= o > > > understand, and about my mistakes. > > > > > > ``` > > > It's business-level, capitalism, if you want so, issue. And it sounds > > like > > > "we won't pay you for your mistakes". > > > > > > There's no magic pill that accidentally forces business to understand= you > > > now need errors collection and it needs at least two more days for > > > "design-level" refactoring without business benefit. Also no magic pi= lls > > to > > > force the business owner to give you that 2 days before you face that > > > requirement (you know, deadlines stuff). > > > > > > Refactoring should be reduced by time as much as possible otherwise y= ou > > > feel more stress on your job. I have no goal to convince you that thi= s is > > > necessary, I solved this problem for myself. But at the language leve= l it > > > can be solved more conveniently and better, and you will also benefit > > from > > > this. > > > > > > All languages work as a stack. So errors could be collected as a stac= k on > > > language level. Directly in place you need that stack instead of > > > everywhere. Also forcing to close applications is safe-shield, instea= d of > > > validation errors that could be found anywhere. PHP devs in most even > > > imagined a solution that "you have to do validation as much earlier a= s > > you > > > can". But... remote api responses still become from inside to outside= , > > > remote api requirements that accidentally arrive still become once yo= ur > > > code is ready, and unpredictable. > > > > > > That simple enhancement allows you to implement error collection and > > > dont touch your methods and signatures. Nice and easy. Or you can bel= ieve > > > in `truth` and deny ideas because it does not correlate with your > > > principles. > > > > Hey friend, easy :) > > > > You was correctly pointed out that this is an application-level issue, > > not a language one. It is your responsibility to collect anything you > > want and deal with the business when it puts some requirements. Did > > you ever experience out-of-memory issues because something in your > > application is collecting some stuff and don't dispose it? Did you > > ever work with algorithms running iterations over millions of records > > in PHP? Can you imagine a language-level bomb if PHP will collect > > anything in its own memory in every iteration of this kind and not > > dispose it during the whole request? > > > > You don't need to reply to me, just take a deep breath and think about > > it. I believe this kind of discussions is an off-topic in this mailing > > list. > > > > > > -- > > Best, Alexander. > > > > > > > ``` > > > > > > =D0=B2=D1=82, 6 =D1=84=D0=B5=D0=B2=D1=80. 2024=E2=80=AF=D0=B3. =D0=B2= 17:56, Arvids Godjuks : > > > > > > > > > > > > > > > On Tue, 6 Feb 2024 at 16:39, Arvids Godjuks > > > > wrote: > > > > > > > >> > > > >> > > > >> On Tue, 6 Feb 2024 at 15:58, =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: > > > >> > > > >>> Hello, please discuss about error collecting implementation in ne= xt > > PHP > > > >>> releases > > > >>> > > > >>> Exceptions have common differences that restrict using them to > > collect > > > >>> errors > > > >>> 1. Timeloss (trace collection) on call new() on any class that > > implements > > > >>> \Throwable > > > >>> 2. To collect errors and return it to the upper level you have to > > change > > > >>> the return signature, so most of the time rewrite the full tree a= nd > > > >>> change > > > >>> all signatures, that's inapplicable and causes more refactor time > > without > > > >>> any benefits > > > >>> 3. Exceptions will break code, so you need to catch them as much > > closely > > > >>> as > > > >>> possible to place you throw it (additional refactoring) > > > >>> > > > >>> What I want from this feature: > > > >>> - while I am writing the api, I need not only "log" the errors, b= ut > > be > > > >>> able > > > >>> to send all script errors to json output, including warnings, > > errors, and > > > >>> deep nested. It will reduce the time of debugging, otherwise i ha= ve > > to > > > >>> download log files from server or configure external system like > > sentry > > > >>> that collects all errors by groups/chains > > > >>> > > > >>> Suggested solution: > > > >>> - add non-breakable interface and language construct `raise` to > > "throw" > > > >>> error without collecting trace > > > >>> - that error could be any scalar or object, or you can implement = new > > > >>> interface for them, keeping that is nested and taggable array > > > >>> - this `raise` could be catched same way as \Throwable allowing l= og > > it > > > >>> anywhere you need or re-`raise` again > > > >>> - `raise` statement won't start to collapse/break code, so it cou= ld > > be > > > >>> skipped without affecting application > > > >>> > > > >>> Current solution: > > > >>> a) 2 classes - ErrorBag/ErrorBagStack. > > > >>> > > > >>> b) native functions like _error()/_warning() that stores errors t= o > > the > > > >>> current ErrorBag if it exists. > > > >>> > > > >>> c) ErrorBag exists only if you initialize it: > > > >>> - from the upper level (you need to collect) > > > >>> - directly inside a function (you need to decide return/continue > > > >>> depending > > > >>> on its emptiness) > > > >>> - otherwise _error()/_warning() does nothing > > > >>> > > > >>> d) once you "catch" results of _error()/_warning() you often need= it > > to > > > >>> merge the result to the current errorbag, mark it with a nesting > > group or > > > >>> with the tag. Nesting group is required once you debug code (you > > will see > > > >>> the log), tags will needed once you want to copy results from one > > bag to > > > >>> another (closest example - reduce queue with unique function, do > > action, > > > >>> then work with initial data) > > > >>> > > > >>> e) useful feature is merge_as_warning($errorBag) - to prevent the > > current > > > >>> error bag to return `true` on call ->hasErrors(). Errors are rela= ted > > to > > > >>> low > > > >>> level function, and possibly you already do actions that allow yo= u > > just > > > >>> store them. > > > >>> > > > >>> f) searching inside the error bag by nesting sequence, or by tag,= or > > by > > > >>> error type. Error type helps the same as try/catch, tag helps if = you > > want > > > >>> to save errors to several destinations without memory losses, and > > nesting > > > >>> will help most of the time in debugging. > > > >>> > > > >>> Thanks for your attention. > > > >>> > > > >>> -- > > > >>> +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 > > > >>> > > > >> > > > >> Hello, > > > >> > > > >> This is an application design-level issue, not a language issue. > > > >> All you need to do is implement a collector on the logger you use = that > > > >> will store the info you want and let you ask for that info just > > before you > > > >> push data into the JSON encoder you use from that logger collector= . > > It's as > > > >> simple as that, you don't even need to change your existing code i= f it > > > >> already logs the information. > > > >> > > > >> -- > > > >> > > > >> Arv=C4=ABds Godjuks > > > >> +371 26 851 664 > > > >> arvids.godjuks@gmail.com > > > >> Telegram: @psihius https://t.me/psihius > > > >> > > > > > > > > Sending me multiple emails in private with rants is not a behaviour > > that's > > > > encouraged on this list. Please read the > > > > https://wiki.php.net/email_etiquette_for_people_new_to_php_internal= s > > > > -- > > > > > > > > Arv=C4=ABds Godjuks > > > > +371 26 851 664 > > > > arvids.godjuks@gmail.com > > > > Telegram: @psihius https://t.me/psihius > > > > > > > > > > > > > -- > > > +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 > > > > > -- > +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 I recommend looking at how other applications handle this. For example, WordPress uses the WP_Error class to collect errors and returns ProperReturnType|WP_Error, and error handling is very similar to Go. Symfony validations simply collect validation errors and an empty array is "all good." Both approaches are totally fine, but it depends on what you are actually trying to accomplish. Robert Landers Software Engineer Utrecht NL