Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:106932 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 21579 invoked from network); 12 Sep 2019 10:42:00 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 12 Sep 2019 10:42:00 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id 5D24A2D209C for ; Thu, 12 Sep 2019 01:17:51 -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,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS36024 206.123.114.0/23 X-Spam-Virus: No Received: from mail1.25mail.st (mail1.25mail.st [206.123.115.54]) (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 01:17:50 -0700 (PDT) Received: from [10.0.1.86] (unknown [49.48.245.106]) by mail1.25mail.st (Postfix) with ESMTPSA id 96EED60445; Thu, 12 Sep 2019 08:17:40 +0000 (UTC) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) In-Reply-To: Date: Thu, 12 Sep 2019 15:17:36 +0700 Cc: Nikita Popov , PHP internals Content-Transfer-Encoding: quoted-printable Message-ID: References: To: Claude Pache X-Mailer: Apple Mail (2.3445.104.11) X-Envelope-From: Subject: Re: [PHP-DEV] [RFC] Reclassifying engine warnings From: php-lists@koalephant.com (Stephen Reay) > On 12 Sep 2019, at 14:40, Claude Pache wrote: >=20 >> Le 10 sept. 2019 =C3=A0 15:31, Nikita Popov a = =C3=A9crit : >>=20 >> On Wed, Aug 28, 2019 at 11:33 AM Nikita Popov = wrote: >>=20 >>> Hi internals, >>>=20 >>> I think it's time to take a look at our existing warnings & notices = in the >>> engine, and think about whether their current classification is = still >>> appropriate. Error conditions like "undefined variable" only = generating a >>> notice is really quite mind-boggling. >>>=20 >>> I've prepared an RFC with some suggested classifications, though = there's >>> room for bikeshedding here... >>>=20 >>> https://wiki.php.net/rfc/engine_warnings >>>=20 >>> Regards, >>> Nikita >>>=20 >>=20 >> Heads up: This RFC may go to vote tomorrow. >>=20 >> Nikita >=20 >=20 > I have objections to those two reclassifications: >=20 > * Undefined offset: %d =E2=80=94 Notice =E2=86=92 Warning > * Undefined index: %d =E2=80=94 Notice =E2=86=92 Warning >=20 >=20 > =46rom experience, having to dutifully initialise each and every key = in an array is burdensome. I understand the rationale of enforcing that = in some coding standard; but whether those particular missing index = should be considered as unexpected (therefore deserving a Warning) is = mostly a question of coding style. >=20 > This is in principle a similar issue as using uninitialised variables, = which, as noted in this thread, is a perfectly accepted coding pattern = in some languages (the issue being distinct from *undeclared* = variables). I say =E2=80=9Cin principle=E2=80=9D, because a perfectly = reasonable coding style may choose to enforce initialisation of = variables, but not of array keys. >=20 > PHP has the advantage of supporting various coding styles. We should = give the opportunity to the users to say declaratively (and precisely) = what, in their coding style, is considered as acceptable, e.g. >=20 > declare( > uninitialized_variables: error > uninitilalized_index: none > ); >=20 > of course, possibly at a package-level declare. That would, for = example, enable people to place legacy code in lax mode and chose a = stricter mode for new code, even letting the precise notion of = strictness vary with fashion without having to review working code = written two years ago. >=20 > That said, as long as those issues are handled as errors (as in: = set_error_handler()) rather than exceptions, one may write a proper = error handler that does the distinction (I do that). However, an error = handler has the disadvantage of being global, making difficult the = integration of code written with differing coding standards. >=20 > =E2=80=94Claude >=20 > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php >=20 I=E2=80=99ve seen a number of people that have concerns about PHP = throwing 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 = undefined constant, etc. Heck, for good measure this mode could even = re-implement register_globals and magic_quotes, because why not?=20 If you want to write sloppy code, that is entirely your prerogative, but = 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)