Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107611 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 87776 invoked from network); 21 Oct 2019 20:10:33 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 21 Oct 2019 20:10:33 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id CFF6B2C5D7C for ; Mon, 21 Oct 2019 10:56:14 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp3.php.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS3215 2.6.0.0/16 X-Spam-Virus: No Received: from mail-yw1-xc2c.google.com (mail-yw1-xc2c.google.com [IPv6:2607:f8b0:4864:20::c2c]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp3.php.net (Postfix) with ESMTPS for ; Mon, 21 Oct 2019 10:56:14 -0700 (PDT) Received: by mail-yw1-xc2c.google.com with SMTP id d192so5225262ywa.1 for ; Mon, 21 Oct 2019 10:56:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=newclarity-net.20150623.gappssmtp.com; s=20150623; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=+z/7KLowAD3gOaWZ56bYefZSofNhT0lrOylHH4JCmAE=; b=nEfaS6JgVBHbq+QJZ1BG3ucmMsLvB5fbtnyeY0lIxDdsABdCi/qZcLsfB6SJRR/ysg xyDsUMES6BWMpAuVaeB3xG2jWb8ftjuUe5m1C4VA4qbSyrONMt0c5F31rH4o2ejYLJ73 PkwCZ7/ym0QyuqUw/DzntVJsM96Zt/F/fP0aWCoOoS7QKeWKitv/AIR6MRY7C8ah7KET cDJ4MyqLWuUezhpGMQSD+VFIcaPdXjxvMK1OT/p5REaVS0I69Ysin3Da0uSl3jRQran1 pu3WmfAvA6ZOVNU/UvXCrO1mXyPphXpFRQfrVJS+KKHiqO129r58WdQhogUzsn0Ud6t+ bJrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=+z/7KLowAD3gOaWZ56bYefZSofNhT0lrOylHH4JCmAE=; b=UaU2Mjpi5mcN52364PXFDq5OUmB/VdMuEVQYUtlLkqsPl7a11fFjvxASYia3SuBUnT pP9vVThExeoyr9GZZfQI/MD0V+S5h94xK40uHW2jx28WzRVElDrHWebDz0uq4Joqrqyb xMzplIlXHhFX/1O1bKcqLblmGG31L30Dz3GtcS/Dq5odz2FJn939AWmurCSx19Ivcz4Q oiVV6vQ7h5K7r1XrUIQ8tYFyypUW3TPhI30GzC7nfYfGGjArlNPgEf41MyQL4lVCwgu+ SLedGek9maXjGHqvhI91fqHdxESqKbeI3LXjpqZrWsDGhcPbvS15XN0GyMCsCTp4tNqm smpQ== X-Gm-Message-State: APjAAAVP+R/UM9/rTSDnPouUDPtR2x3VuLrItB0PL8wrP5GrAtGa2a5s ztPKPqiHeDKxXRwCzCwj8YryfQ== X-Google-Smtp-Source: APXvYqyZtOphIWyJjHEnTc7/15frGCW0CwtZ9BCRgbPW4LwMv7VpEpF0WmWZf+Cb7Nbks1wjHZ6r6w== X-Received: by 2002:a81:22c2:: with SMTP id i185mr100217ywi.402.1571680573336; Mon, 21 Oct 2019 10:56:13 -0700 (PDT) Received: from ?IPv6:2601:c0:c67f:e34e:90d7:91e4:da1d:b8e6? ([2601:c0:c67f:e34e:90d7:91e4:da1d:b8e6]) by smtp.gmail.com with ESMTPSA id y205sm3633279ywc.6.2019.10.21.10.56.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 21 Oct 2019 10:56:12 -0700 (PDT) Message-ID: <1451C117-D656-472D-9FD0-642351300BD9@newclarity.net> Content-Type: multipart/alternative; boundary="Apple-Mail=_7D8EBDAA-8BF6-4D87-A321-79894C7A62AA" Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Date: Mon, 21 Oct 2019 13:56:11 -0400 In-Reply-To: Cc: internals@lists.php.net To: David Negrier References: X-Mailer: Apple Mail (2.3445.104.11) X-Envelope-From: Subject: Re: [PHP-DEV] Reclassifying some PHP functions warning as exceptions From: mike@newclarity.net (Mike Schinkel) --Apple-Mail=_7D8EBDAA-8BF6-4D87-A321-79894C7A62AA Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Oct 21, 2019, at 5:10 AM, David Negrier = wrote: >=20 > Hey list, >=20 > TL;DR: >=20 > I'm considering writing an RFC (and a patch) to turn some warning into > exceptions in a number of PHP functions. > I would first like to gather some feedback here. JMTCW, which is an opinion admittedly probably not shared by most who = work with PHP, but I find exceptions problematic and try to avoid them = whenever possible. I have again included this list of references[1-6] = to explain why I found them problematic, which I had mentioned just = yesterday on an unrelated message to this list. The idea that functions that I could previously dealt with in four lines = of code: $filepath =3D __DIR__ . '/foobar.json'; if (false =3D=3D=3D ($content =3D file_get_contents($filepath)) ) { error_log( sprintf("failed to open '%s'", $filepath )); return false; } Will potentially now requires me to add a second brace-enclosed block = and two more lines of code and force me to handle varying exception = classes causes me to cringe and will make me want to cry: $filepath =3D __DIR__ . '/foobar.json'; try { $content =3D file_get_contents( $filepath ); } catch (Exception $exception) { error_log( sprintf( "failed to open '%s'", $filepath ) ); return false; } Since I know that many in the PHP world believe that exceptions are a = good thing, I understand that I will be unlikely to change everyone's = mind and get them to start doing error handling as soon as they discover = the error rather than just throw it and let some other code that doesn't = have as much context deal with it. =20 But my hope is at least PHP won't change to force having to use = try/catch for practically every function call. Such a change might even = be enough to finally get me to give up on PHP and move full time to Go = because it will make coding in PHP so tedious. For me to support such a change =E2=80=94 not that I have a vote =E2=80=94= I would ask we add a pragma that could be set at the top of every file = that specifies that functions throw exceptions or return errors, and for = BC please make the lack of such pragma to default to returning errors. =20= Or better yet, accept Benjamin Morel's suggestion to create a brand new = API for this rather than attempting to fix the existing one. One of the other. Please. -Mike P.S. Frankly =E2=80=94 in my perfect world =E2=80=94 we would have = options to not throw Exceptions for everything that currently throws an = exception and instead return an Error object value that indicates the = error. They could even return the Exception =E2=80=94 that would work = =E2=80=94 just don't throw them so I do not have to set up a = `try{}catch(Execption $e){}` construct. Just the other day I had to deal with the fact PhpStorm flags functions = that return Exceptions if I don't handle them, and `new DateTime()` = throws an Exception because it's optional parameter could cause a = failure, even though I was not passing in any parameter. I had to wrap = in my own `TryCatch()` function that basically just buries the Exception = to get PhpStorm to stop complaining. But I do not hold out much hope for having an option to bypass all = Exception ever being accepted by the PHP community. [1] http://www.lighterra.com/papers/exceptionsharmful/ [2] https://sidburn.github.io/blog/2016/03/25/exceptions-are-evil [3] http://xahlee.info/comp/why_i_hate_exceptions.html [4] https://www.joelonsoftware.com/2003/10/13/13/ [5] https://mortoray.com/2012/04/02/everything-wrong-with-exceptions/ [6] https://www.atlassian.com/blog/archives/exceptions_are_bad= --Apple-Mail=_7D8EBDAA-8BF6-4D87-A321-79894C7A62AA--