Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113408 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 1904 invoked from network); 6 Mar 2021 15:46:03 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 6 Mar 2021 15:46:03 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0303D1804C3 for ; Sat, 6 Mar 2021 07:37:18 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sat, 6 Mar 2021 07:37:17 -0800 (PST) Received: by mail-ej1-f52.google.com with SMTP id lr13so10103966ejb.8 for ; Sat, 06 Mar 2021 07:37:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=glil9oA5/YexOXmoooWKcjFe3HHyfKIfAt5l1ugjsAQ=; b=Q4kOwz75YF1S9UPVcPUrCCEFvXN8ApkTYsnTjfcK1+QPWWLKquA690IoQWzaUActC9 o2/BCaFzoSl1ZTA92ABYfyufnd6zGni69VS2SSyGNyOnTEtNl53cKiNqOqbEFzIRlo5H mtYqYEHOMT9bF7yzPb5P7zAGkmMLrCgZEm4TYAUmctvrEISQ78CPrrLUdHmVW/Cl3ZBI VriAa0f8vccsxkGmZpeo+Dc95Zvi2uXDhkOnIrrLu1800o3JHn/T7Jx8kXF5PJFDXz5m 4lpVuiL9DcPMQy//jwJgrlvfh3m8bvUA2UvpHrgiQCPr3KwjNdWeACeP/J7J0Avd07ft KpkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=glil9oA5/YexOXmoooWKcjFe3HHyfKIfAt5l1ugjsAQ=; b=qLhMli2zYQY1tvgO/PxbzPOqPwSlswpp7ox8rX6MUXi3tOqsvOjqPJ/vLholnil+Ay txuDvEme4/98aBr9BOXJcvFScenB8xs35wX28WIZS70T5q23Bee3Xaj5qUO0XkMSfvdB y8kr4i/X8CL3aNyodjBWdw6Ja69oTpmRqjqvhmyzADiuc7YwqtodW++yRLhmEkFep2Ao NJqZMYqlhZG5EJjeHF4hvN1mTmhc68LljyUalrXeq957De/2FpsxWQuseAgmBFa+Vv1W wpi/RKIiknam1C6nrRou4Oc3lEvZs5crtZ7lEoTQI5ogRSz9JnMXCOht7CtNvUT5j0rV ZSMA== X-Gm-Message-State: AOAM532hb3klwxLbiUFRyWvGnlH6UU15XG/znjozXegxec4rlsNjFaXA TnbRkz9suPVvyElXoWGHNmSvc+zQhRu/OcnCT18= X-Google-Smtp-Source: ABdhPJw8AYjK+RnNM2L2n3mMqNBZEhKIKCMHF2PX527ATyWUJh4fnPkONgrhRI8fOzWog+cmFnYBjbkm4k6MG9659NM= X-Received: by 2002:a17:906:fa0e:: with SMTP id lo14mr7241326ejb.263.1615045036138; Sat, 06 Mar 2021 07:37:16 -0800 (PST) MIME-Version: 1.0 References: <7D86BD2A-3D54-41A1-8BAE-2E65AB155271@newclarity.net> In-Reply-To: Date: Sat, 6 Mar 2021 15:37:05 +0000 Message-ID: To: Rowan Tommins Cc: PHP internals Content-Type: multipart/alternative; boundary="000000000000ace41b05bcdff9d1" Subject: Re: [PHP-DEV] [RFC] Extend error control operator to suppress exceptions From: george.banyard@gmail.com ("G. P. B.") --000000000000ace41b05bcdff9d1 Content-Type: text/plain; charset="UTF-8" On Thu, 4 Mar 2021 at 22:05, Rowan Tommins wrote: > On 04/03/2021 14:08, G. P. B. wrote: > > This new RFC which I'm proposing is to extend the capability of the error > > control operator @ to not just suppress diagnostic messages but also > > exceptions. > > It can currently be found on GitHub: [1] > > https://github.com/Girgias/error-control-operator-exceptions-rfc > > > Hi George, > > This is a really creative approach to this thorny problem, and I think I > like it, although I'm still working through the implications in my head. > > > One thing I'd like to call out is that this could be useful in its own > right, outside of migration strategies. > > One of the big downsides of exceptions is that they always cause control > to jump somewhere else, even when you'd rather they didn't. Joe Duffy in > an interesting blog post [1] about error handling strategies refers to > it as "control-flow rather than dataflow". > Took me a while to read this article, which was very interesting. > For instance, if you start with this: > > $foo = doSomething() + $bar; > > If doSomething() throws an exception, and you want to default to just > $bar, you have to write this: > > try { > $foo = doSomething() + $bar; > } > catch ( SomeException $e ) { > $foo = $bar; > } > > What you really want is to catch the exception, but not break the flow. > With this proposal you could: > > $foo = ( @doSomething() ?? 0 ) + $offset; > > > Which leads me to suggest changing this: > > > As such @<\Throwable>expression and @expression are identical. > > To this: > > > When a class list is given, the operator will not suppress raised > errors (E_WARNING, E_NOTICE, etc). So @<\Throwable>expression will > suppress all possible Exceptions, it does not have the same behaviour as > @expression. > > This makes the operator useful even in situations where you want normal > error handling behaviour (e.g. logging) for Warnings and Notices, but > want to force an exception back into "dataflow style". > This is an interesting idea, and relatively easy to change with my current PoC. However, in that case investigating how to prevent the creation of the exception altogether is something that will need to be investigated as the creation of an exception remains expensive On Sat, 6 Mar 2021 at 13:57, Rowan Tommins wrote: > That means a lot of people would still need to change their code if > fopen() started throwing exceptions, weakening advantage #2. > > > If you make people opt into exceptions, e.g. using > declare(throw_on_error=1) then you actually lose *both* advantages: > > 1. Every file you add the new declare() line to will no longer run on > older versions of PHP. > 2. Since you're changing every file anyway, in a non-compatible way, you > can do some find-and-replace at the same time. For instance, changing > "if(@fopen($filename))" into "if(try(fopen($filename)))". > > I'm also not convinced a file-level opt-in is a sensible long-term > strategy. The risk of writing code assuming one error style in a file > actually set to the other seems too high. > Frankly I would prefer this to be part of an edition mechanism as I would not want this to be a permanent addition to the language due to the disadvantages that you've listed which I am aware of. But until such a mechanism is introduced into PHP, a declare statement is the best next thing that I can think of. > The more I think about it, the more I get the feeling that while this > proposal has some great ideas, it hasn't got the combination quite right > yet. > And that's why I'm publishing it on the list, because the issue is rather complicated and I don't think I can figure it out on my own. > Regards, > > -- > Rowan Tommins > [IMSoP] > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > > Best regards, George P. Banyard --000000000000ace41b05bcdff9d1--