Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113406 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 93203 invoked from network); 6 Mar 2021 14:05:56 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 6 Mar 2021 14:05:56 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 5BF351804C3 for ; Sat, 6 Mar 2021 05:57:11 -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,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) (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 05:57:10 -0800 (PST) Received: by mail-wr1-f47.google.com with SMTP id u14so5644146wri.3 for ; Sat, 06 Mar 2021 05:57:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=bYyHPyQz+DVllsTxAeiZSuGiAylecC504p00APmIx9I=; b=ufC225iLLGT71E8ETd/MjYmXgW3iWIAOaA627lLmH/iiyhJg+4XFJE/9PCKbGjGoOj jmH7Kn3nJNbWbU50RyoCR+00q7dTVbNakzlsgXkXLFVtkriFz6Yw6/Af9jJcARCvq1fZ zBVNgKFJV9ivvgwYyAwdzBXcgIWqOgdWQXXJHZepxgNd98ULDHu3cJDZlGJnEG+MWpvn 12PwMOIwqzwkSLWP9jhTGaV639lGaHjSPSmPhr/82OX1Ja46ZYpOEABkCXc75ajpRf+2 PFYf0RRqJSKL1TRqpenKb+Y1XhjeNpcMSoCT6MTILTc117GwrikNvBUtk4guSBAgiiT2 80gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=bYyHPyQz+DVllsTxAeiZSuGiAylecC504p00APmIx9I=; b=lavXXtNwBOQJeNzrBzbjW/t7FbWeIXbVwf/jtJBrq2SzF1Qi1SXkZuReYH/14+xhUo j7j+gV/kjsENcWZ+W+K/Zkd40byu/NkhYWQ8UxS0BIhZnQS47HiAL7XeiwptXFeoGkMW nKRL89J7NW8y9vomuaNPgZFC7RXz4dRpAFCVlqdYPMtcts6kbS+5k4H01kQRP0c52UtU QVUjaGrDc7UjOr7dfzaX6D5qNzZrhFhqpbpVo2xxqfvhCormuj1mULcwzxfTD6p4oT2Y ElDvxJ/Og0eRBV4w+TlKGKXTcbakGE7BWfbgoe2wNAgMZnanCMPn+rA05hjC/1h7eGNp 60MA== X-Gm-Message-State: AOAM530cy1r0V3zaFHcGHeV/fOxCubsNbndsLAKbuqW4BmZNVhHXy43w 2m5MpxI1d6k2drkj0m6vJgMHZVHd2K8= X-Google-Smtp-Source: ABdhPJziI6xr4rgv9AZwf47d8O/eReS5umOOBXz7cKbL/89hSuhI2RjUhpotne+5SX0XR77zY6snoQ== X-Received: by 2002:adf:e38a:: with SMTP id e10mr14389896wrm.37.1615039022101; Sat, 06 Mar 2021 05:57:02 -0800 (PST) Received: from [192.168.0.22] (cpc104104-brig22-2-0-cust548.3-3.cable.virginm.net. [82.10.58.37]) by smtp.googlemail.com with ESMTPSA id c128sm26648701wme.3.2021.03.06.05.57.01 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 06 Mar 2021 05:57:01 -0800 (PST) To: internals@lists.php.net References: <7D86BD2A-3D54-41A1-8BAE-2E65AB155271@newclarity.net> Message-ID: Date: Sat, 6 Mar 2021 13:56:58 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.8.0 MIME-Version: 1.0 In-Reply-To: <7D86BD2A-3D54-41A1-8BAE-2E65AB155271@newclarity.net> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-GB Subject: Re: [PHP-DEV] [RFC] Extend error control operator to suppress exceptions From: rowan.collins@gmail.com (Rowan Tommins) On 05/03/2021 04:26, Mike Schinkel wrote: > 1. What @ means and what it would look like in practice, > 2. What catch(union_class_list) would look like in practice, > 3. What @<\Throwable>expression means and what it would look like in practice, and > 4. Can you provide a few concrete code examples, please? I think I can help out here. "union_class_list" is just referring to the fact that a catch clause can (as of PHP 7.1) list multiple exception classes in it, using the same syntax as union types: "catch(FooException|BarException $e)". So an example would look like this: $foo = @fopen($bar, 'r'); Which translates to: try { $foo = fopen($bar, 'r'); } catch (FileNotFoundException|InsufficientPermissionException) { $foo = null; } > I am not clear what you mean by "providing a path to migrate in a BC manner" here. Would this require developers to prefix all functions calls with @ for functions changed in a future version of PHP to throw exceptions instead of returning values, assuming they do not have the green light from their stakeholders to make more substantive changes to their code? Rather than "having the green light from their stakeholders", I'd focus on the more straight-forward "want upgrading to be as easy as possible". The two advantages that I see in using @ specifically for this are: 1. It is valid syntax in existing versions of PHP, so code using it can be compatible with multiple versions. 2. A lot of people already use it with functions like fopen() to suppress the expected warning, so would have to make no change at all. The problem is that not everybody does prefix, say, fopen() with an @. Some people just live with the noise in their logs of the occasional Warning; others use an alternative mechanism to suppress it, such as wikimedia/at-ease [https://packagist.org/packages/wikimedia/at-ease] 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. 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. Regards, -- Rowan Tommins [IMSoP]