Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107603 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 55488 invoked from network); 21 Oct 2019 17:43:12 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 21 Oct 2019 17:43:12 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id 0CC872C0544 for ; Mon, 21 Oct 2019 08:28:53 -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=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,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-io1-xd32.google.com (mail-io1-xd32.google.com [IPv6:2607:f8b0:4864:20::d32]) (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 08:28:52 -0700 (PDT) Received: by mail-io1-xd32.google.com with SMTP id c25so16356286iot.12 for ; Mon, 21 Oct 2019 08:28:52 -0700 (PDT) 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=FMDlrHi+9U6zMSV7b9FDOpF8In/H6t3y/L5U6umoI2o=; b=AvyZgvN7e+OLDH5nlvpitr6iQoDtVeg08hmsaH0aci9nGHTO4/i1JlCDr2Fc1wN0AU t2aFKgPyOxIV9jJP5b/nwD4oW7QY/8/l2hnS7gphT6Wt67JildASHoh8jAbAmuYvMiEn SQ87K3K9KtB5luYpKJUeAVKPPTf3Z/MctC85qAiPLBJXeJCpeQqLJEBh1DKG5rZQvT/Y zPVcZCzIG/XdyuvzfyrLsf1Ua1Q2hKFYfoSye3BtLj9r5m5UwHz0CvaMSAWXCpslO7nV RwKHE3RBbaosNW1KUu5N6rQIbWRnHkZsUYI4t3MCfNBY978G7muJu/9kctpKm12V9cgi BmuQ== 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=FMDlrHi+9U6zMSV7b9FDOpF8In/H6t3y/L5U6umoI2o=; b=Po0eZqoX42v2F+IsNJkluuEZw0stVw2wb4je/9PXC7TSAKwiFsOYM3w3FcdYFGUnAg WWA3Qf+E0XaGTAKs1uJHiEict1lC6kXMnC5UX8VWUuOI6ja09iBbEhK++BFRiMsv0xT+ E1X3ju8G4Lqi/jC+/nCvvTbs0M3vgnyFLVH1cL8S59KTiHNux2jGxXfJ7jrrotRIK8y3 EHp1pKe8bZw3vd4CWbd3BgS8amtNZF72/FJqww1udQvLfxYkHiYod+pyt/sa7tJHrcpt WnnAJ+rDls8NbEHtngjzCS8OLFhvhAANth2DUvLh42r6bQlz3hpiFqWaXJtvWIfL09G7 M3xg== X-Gm-Message-State: APjAAAXgJzKSiXIdajDzLeFa2rCi71p8MZeQq73Z7d1tXmu93DKfDMcn bWCZpOB1L9ccSpzhAlTdXr2f3lLi5VCGUlPWR/XJ5oEq X-Google-Smtp-Source: APXvYqzWPVyXZKh5QLJ/St+p55bXAxeOWPiLylEjxYJraU10SRralrjKlveJ+TFgabj7VdwrklBNtFCpEGtf5bY1LTY= X-Received: by 2002:a6b:6405:: with SMTP id t5mr21414618iog.93.1571671731781; Mon, 21 Oct 2019 08:28:51 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 21 Oct 2019 17:28:39 +0200 Message-ID: To: David Negrier Cc: PHP Internals Content-Type: multipart/alternative; boundary="00000000000046c69b05956d5752" X-Envelope-From: Subject: Re: [PHP-DEV] Reclassifying some PHP functions warning as exceptions From: benjamin.morel@gmail.com (Benjamin Morel) --00000000000046c69b05956d5752 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable > 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. I would *LOVE* if these functions could be fixed, and if I had the almighty merge button at my disposal, I'd press it whenever such a PR is proposed. To play the devil's advocate, however, IIRC some discussions in the past mentioned that the BC breakage that comes with it is such an issue that it would be preferable to create a brand new API rather than attempting to fix the existing one. Nobody ever jumped in to propose such an API, though :-( =E2=80=94 Benjamin On Mon, 21 Oct 2019 at 15:52, David Negrier wrote: > Hey list, > > TL;DR: > > 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. > > The long version: > > It is the first time I'm posting on internals. > Some of you may already know me. I'm one of the authors of > thecodingmachine/safe, a library that wraps all PHP functions that return > "false" on error in similar functions that will throw on exception on > error: https://github.com/thecodingmachine/safe/ > > Surprisingly enough, I've had a huge positive feedback with Safe (I reach= ed > 1000 stars on Github in a few weeks, so I think I can say this is somethi= ng > that bothers a lot of people). > > Of course, I could simply have written an error handler that would turn > E_WARNING into exceptions but: > > - For some libs, I wanted to write code that would behave consistently > (whatever the settings of error_reporting) > - More than all, having a return type that can be "string|false", or > "object|false" is a true annoyance when you want to write type-safe code > (which is more and more common with the advent of tools like PHPStan or > Psalm). > > For instance, "sprintf" can return "string" or "false" (in case the forma= t > is incorrect). If the string passed to "sprintf" is invalid, I would > certainly prefer knowing right now (with an exception) than risking havin= g > the warning sleep under my nose. > > Needless to say: a good practice in error handling is "fail loud, fail > fast". A warning at some point will most certainly lead to an error a few > lines later if error handling is not done properly. > > If you look at the frameworks out there, I believe all of them are shippi= ng > with an error handler that throws exceptions by default (even on notices)= . > > Also, my team and I are starting to spend a lot of time maintaining Safe. > So I started wondering if rather than spending time maintaining a patch i= n > user land, we could not instead spend time fixing things in the core. > > So here we are, my team and I started playing with php-src. We are not > regular C developers, but we managed to write a small patch to turn > "sprintf" warnings into exceptions. > > This is far from ready but the PR is here: > https://github.com/php/php-src/pull/4837 > > We would be happy to promote more warnings to exceptions as those: > - are more predictable > - can be more easily caught / handled > - enhance the type system by removing the "false" return type > > This is going in the same direction as Nikita RFC's regarding reclassifyi= ng > "Engine Warnings". > > I understand there have been a lot of discussions going on recently > regarding maintaining backward compatibility vs evolving/sanitizing the > language and I know this is a sensitive topic. > > That being said: > > - most frameworks are already providing an error handler that turns warni= ng > into exceptions (so they should not be impacted by the change) > - there are a huge number of warnings that can be turned into exceptions > with minimal impact ("sprintf" E_WARNING are clearly a good first > candidate) > > Ok, so my team and I are willing to put some time to turn some of those > warnings into exceptions. I understand there are some questions to be > answered regarding the nature of the exception (what class, what class > hierarchy...) > > My questions: > > 1- Do you think there is a chance an RFC on this topic might be accepted? > Shall I start working on it? > 2- Shall we start working on a list of candidate functions? > > David > --00000000000046c69b05956d5752--