Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:81290 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 10824 invoked from network); 28 Jan 2015 08:43:54 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Jan 2015 08:43:54 -0000 Authentication-Results: pb1.pair.com smtp.mail=kontakt@beberlei.de; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=kontakt@beberlei.de; sender-id=unknown Received-SPF: error (pb1.pair.com: domain beberlei.de from 74.125.82.41 cause and error) X-PHP-List-Original-Sender: kontakt@beberlei.de X-Host-Fingerprint: 74.125.82.41 mail-wg0-f41.google.com Received: from [74.125.82.41] ([74.125.82.41:61683] helo=mail-wg0-f41.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 92/7A-45774-841A8C45 for ; Wed, 28 Jan 2015 03:43:53 -0500 Received: by mail-wg0-f41.google.com with SMTP id a1so19227100wgh.0 for ; Wed, 28 Jan 2015 00:43:49 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=Ezw3UbrXysTDBcE0y1yqE1A8kbRNEIYbXaqFaS746ts=; b=UvRG4E2Un1H8E3H4/Cvn9otno2GLodoD9OMk8sVawfEb+mJT8LLsyz+sYOPx/wR2UY 38dh2h1fThqhpHOOhDy1/Ct7OIHJeDAPCcYXAr5D/2iwE50Jvp0rUDb0olhSlKw0AG2j LEi6butteTZ9ju6WaVvFmnPNvj8+kBKz9fqtVlGDmQz67cFYjIka+6F8giq66E+Yd4y9 Iu/3/sGSmC1v07cXez2H0mKoQL9i8lBVY2XW1RipwDa9jhLIAF01ry+z6hjrQRSQsq0e QRAOZ4d3aQDqJKGCD7RIN/RGhFSkbSCCFIZ3SntMWbSZhYLpbENCqzlMq2UqTTG6/hie fpeQ== X-Gm-Message-State: ALoCoQnGDqSiwDNNLDZvzQb+pigjOKrLymouOdyCp7QUUiY7EbWm4pGYzl6+viOHfGkrNMC2ptX+ MIME-Version: 1.0 X-Received: by 10.180.75.199 with SMTP id e7mr4726288wiw.21.1422434628076; Wed, 28 Jan 2015 00:43:48 -0800 (PST) Received: by 10.194.133.69 with HTTP; Wed, 28 Jan 2015 00:43:47 -0800 (PST) X-Originating-IP: [77.11.86.252] In-Reply-To: <54C80F4F.7020905@gmail.com> References: <54C80F4F.7020905@gmail.com> Date: Wed, 28 Jan 2015 09:43:47 +0100 Message-ID: To: Rowan Collins Cc: PHP Internals Content-Type: multipart/alternative; boundary=f46d04389577b91bf6050db25ead Subject: Re: [PHP-DEV] Proposal: Raise severity of undefined constants From: kontakt@beberlei.de (Benjamin Eberlei) --f46d04389577b91bf6050db25ead Content-Type: text/plain; charset=UTF-8 On Tue, Jan 27, 2015 at 11:21 PM, Rowan Collins wrote: > Hi All, > > I would like to propose that the error given for an undefined constant > should be raised from E_NOTICE, probably to E_RECOVERABLE_ERROR, in PHP 7. > > I'm happy to expand this into a proper RFC, and work on patches for the > engine, tests, and spec, but want to see if initial reception to the idea > is favourable first. > > Current behaviour: any bare word which is not a defined constant is > treated as though it were a quoted string, with an E_NOTICE issued. > > Proposed behaviour: an E_RECOVERABLE_ERROR is issued; if the error is > caught, either the existing string behaviour could be retained, or the > value could be treated as NULL. (I'm open to other alternatives.) > > PROS > > 1. Consistency. > > An undefined class constant (e.g. Foo::BAR) gives a fatal error, but a > normal global constant gives only a notice. Class constants being "more > modern" made this seem reasonable, but with namespaces, it's even worse - a > qualified namespace constant (e.g. Foo\BAR) gives a fatal error, as does a > global constant in namespace notation (e.g. \BAR); but a namespace constant > referenced relative to the current namespace is a bare word, and gives only > a notice (e.g. namespace Foo; const BAR=42; echo BAAR;). > > Functions and classes also give fatal errors if used without declaring; > variables do not, but this is more useful, because they can meaningfully be > created as null, and there isn't a syntax to declare a local variable, only > to initialise it. > > 2. Inherent severity. > > It's probably relatively common to turn off E_NOTICE in error_reporting, > or to miss one notice among many others. But an undefined constant > magically turning into a string could cause relatively major problems. > > Firstly, a constant is likely to have some value which needs to be used or > matched somewhere else. A READ_ONLY flag mis-typed as REED_ONLY could be > interpreted as int(0) (i.e. intval('REED_ONLY')) and cause a catastrophic > error. > > Secondly, keywords are also bare words, and any expression can be a > statement. Thus the following is an infinite loop, no matter what > blahblah() returns: > while(true) { > if ( blahblah() ) { > brek; > } > } > > Obviously, there are other mistakes which could cause such errors, but > this is one that the engine could easily pick up on and protect the user. > > > CONS > > Like most changes, the downside is a break in compatibility. > > As far as I can make out, the current behaviour is actually for > compatibility back as far as PHP 3 (correct me if I'm wrong, I didn't dig > far). > > I'm not aware of any notice officially deprecating barewords-as-strings, > but nor can I find many references to it in the manual at all. Its use for > array keys has been explicitly discouraged in the manual since some time in > 2001. [1] > > Outside code golf, I'd be very surprised if any code written or updated in > the last 10 years deliberately uses this "feature", and I think changing it > in PHP 7 is justifiable given the benefits to maintainers of even the > simplest non-OO, non-namespaced code. > > > What do people think? > I think this is too big a BC break. The usage of $array[key] = 0 instead of "key" is widespread. > > [1] http://web.archive.org/web/20010614144157/http://www.php. > net/manual/en/language.types.array.php#language.types.array.donts > > Regards, > > -- > Rowan Collins > [IMSoP] > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --f46d04389577b91bf6050db25ead--