Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:106936 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 50671 invoked from network); 12 Sep 2019 12:56:36 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 12 Sep 2019 12:56:36 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id 052A12D20BD for ; Thu, 12 Sep 2019 03:32:28 -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,URIBL_BLOCKED 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-xd42.google.com (mail-io1-xd42.google.com [IPv6:2607:f8b0:4864:20::d42]) (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 ; Thu, 12 Sep 2019 03:32:27 -0700 (PDT) Received: by mail-io1-xd42.google.com with SMTP id r26so53158259ioh.8 for ; Thu, 12 Sep 2019 03:32:27 -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=XqAMfFAjajfrDTqo/aNyiPVrnqoeYHd/CJaLVtAiqHM=; b=PO/Lnz4EHBuHdCkBH3YUtu1Jk3HUhsx0RdhUSqKsnOcLJK5V33ezYjzyfm+3pkX3qv pqiD7i6ch8TJu5WfDsErLLeLxdAXzFdrpuL8XSu2R6tELuGrgV+Texg6VkFU+6Kz7gaY zU2GyqrdkSzf8xbJ4H1tg5hzWd99LEz/NsVnO8K1TVbk06MOgVG7Ma4r2BD4uy5WU/i0 9YJEgdIONtGHUXsRJtb8/Zj2AOjqDb2iYGAaHOVQGJU9gZxNyO+gb1b2/mn5bWwqELO0 VxhNUGhnLeofVkuhGxwae8J8YbRIhqwCMVwUCx2bifXwvYONsO4NaFg0M/YNrpC3pYYI YJ2Q== 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=XqAMfFAjajfrDTqo/aNyiPVrnqoeYHd/CJaLVtAiqHM=; b=H2vmu1r/yiH4dD/rvlx8+0Nko+fdHAP4ty6do+XfI0BIvVgMILqc8WK3eWCD63XrOZ f3kpFXMxNL4ZY1Go4MHW2S89ZW15ZaypOAjYKO1Emz46jHLjH2uLxz0WBpU1CeZrUSRU w+9uARFTO4s8cPCtmKYCMPQlmaKj9+EievNKPdN3IX5Vria54lRgZ4otZQyTrXbMNz0l Gu/n8T8wlgTYITTVpdR5OCs+Qzb8B9ljSPEUo9UpRJCcuhnLK1nXmPR21MPRxMpXy/Cm ouJrDTeqWCficbp+82gxmEP/YIjY5dZgcKOXecPwR3hRQxRxuAPfnduUvpQ7AD6/EIgW uu3w== X-Gm-Message-State: APjAAAWZzTWak3ikaPLMFuyeLHAfmqkYfh0AhTX/GVhMZiShOTml0Mhf DB5qNE+CjYL95If70N3cvhWORHpG7Ij0GiP3Hrs= X-Google-Smtp-Source: APXvYqxxWG+Qr2ylgJszrLenW7hEQdPk5fFLjDDs5QX7WcrY8+NfV4QVdLMiZJhXGhqyn4ZxFL8a0Vev92RXZp5i1ag= X-Received: by 2002:a6b:db0e:: with SMTP id t14mr3449744ioc.93.1568284346527; Thu, 12 Sep 2019 03:32:26 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Thu, 12 Sep 2019 12:32:14 +0200 Message-ID: To: Claude Pache Cc: Stephen Reay , Nikita Popov , PHP internals Content-Type: multipart/alternative; boundary="00000000000061b43a059258a78f" X-Envelope-From: Subject: Re: [PHP-DEV] [RFC] Reclassifying engine warnings From: benjamin.morel@gmail.com (Benjamin Morel) --00000000000061b43a059258a78f Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable > > For example when I=E2=80=99m writing a throw-away script, some notices ar= e okay to > indicate possible problems Maybe it's just me, but even in throw-away scripts, *I've lost much more time because of warnings/notices going unnoticed, than I've saved thanks to PHP's forgiving nature*. Hence even in the shittiest of my scripts, I usually end up registering an error handler to throw an exception even for the smallest notice. At least, I always get an exception right in my face when something's unexpected, so I can fix it and move on, and avoid surprises later on. Sure, in a quick script, I do see some value in being able to write stuff like: @ $array['non_existing_key']++; It's still sloppy though: what you're really doing is muting a notice and incrementing null. Instead, I feel like there should be a stronger support from the language to specifically handle this kind of use cases, rather than using them as a justification for not *severely *hardening error reporting. I don't think there are that many such *potentially *legitimate use cases, so maybe we could just list the use cases and think about a more elegant solution to solve them? In other words, if that was only me, the whole notice/warning stuff would go, and PHP would only have exceptions. Undefined variables would throw, undefined array keys would throw, and use cases like the above would have stronger language support to avoid boilerplate code full of if(isset()). =E2=80=94 Benjamin On Thu, 12 Sep 2019 at 11:42, Claude Pache wrote: > > > > Le 12 sept. 2019 =C3=A0 10:17, Stephen Reay = a > =C3=A9crit : > > > > > > > > I=E2=80=99ve seen a number of people that have concerns about PHP throw= ing > actual errors (as opposed to notices) because they try to use a > variable/offset that doesn=E2=80=99t exist, and of course there is often = a proposal > to have a declare statement or something similar, to allow their =E2=80= =9Ccode > style=E2=80=9D to run without errors. > > > > > > So, my proposal to the situation is to introduce a single declare that > solves that problem, once and for all. > > > > > > declare(sloppy=3D1); > > > > > > This would suppress any errors about undefined variables, array offsets= , > would reverse the =E2=80=9Cbare words" change when encountering an undefi= ned > constant, etc. Heck, for good measure this mode could even re-implement > register_globals and magic_quotes, because why not? > > > > > > > > If you want to write sloppy code, that is entirely your prerogative, bu= t > please just own it for what it is, and stop pretending that it=E2=80=99s = some > herculean task to either define variables/offsets first; or check if > they=E2=80=99re defined; or use an appropriate method to access them that > specifically allows for undefined variables/offsets (i.e. the ?? and ??= =3D > operators) > > > > > > Declare(sloppy=3Dyeah) is not granular enough. To all: please, do underst= and > that everything is not black or white; this remark is not directed > specifically to that particular issue, this is an attitude I see regularl= y > on that mailing list. > > There is no such thing as =E2=80=9Cone true strict coding standard=E2=80= =9D and =E2=80=9Cone > legacy lax coding standard=E2=80=9D. For instance: > > * As time passes, we learn by experience what features were plain blunder= s > (magic_quotes?), what features should have been more strict for the sake = of > catching bugs without imposing too much burden on users, what features > could have been more strict, although that would impose to write lot of > boiler code, etc. This process does not belong exclusively to some past > dark age of sloppy and unsecure coding practices. > > * The degree of wanted strictness vary depending on occasions. For exampl= e > when I=E2=80=99m writing a throw-away script, some notices are okay to in= dicate > possible problems, but I=E2=80=99m not going to write boilerplate code (o= r, worse, > put a @ in front of everything) just for the sake of silencing them. (But= I > *certainly* do not want stupid things like mistyped constants converted t= o > string literals.) On the other hand, when I=E2=80=99m writing a critical = part of an > application, I am careful to write down everything precisely, and having = to > write explicitly and once for all that, yes, this precise variable must > have that default value, is a minimal part of the time passed to write, > re-read and review the code. > > =E2=80=94Claude > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --00000000000061b43a059258a78f--