Re: [VOTE] Shorter Attribute Syntax Change

From: Date: Wed, 12 Aug 2020 19:08:18 +0000
Subject: Re: [VOTE] Shorter Attribute Syntax Change
References: 1 2 3 4 5 6  Groups: php.internals 
Request: Send a blank email to internals+get-111497@lists.php.net to get a copy of this message
On 12 August 2020 19:03:02 BST, Jakob Givoni <jakob@givoni.dk> wrote: >> > Is >> > >> > <?php @[Bar()]; ?> >> > >> > on it's own an error? >> >> Yes. Basically this is an example of valid code in PHP 7 that will >> break if @[] is adopted. > >Wow, that was unexpected. By what logic? >Also, how long must I wait before I can put a semicolon after the new >attribute syntax? Is one whitespace enough or do I have to go to a new >line? >To me, suddenly disallowing semicolons at some points between >statements or between a "declaration" and a statement seems to break >PHP logic. It's not that the semicolon is forbidden as such, it's that the code is interpreted completely differently. Imagine if we had no "private" keyword, and then added it; this would previously have been valid (a statement followed by a declaration): private; function foo () {} But once "private" is a keyword, that is a syntax error. Removing the semicolon happens to make a valid declaration using the keyword, but that's basically coincidence: private function foo() {} The same is true of attributes, which as others have pointed out are similar to visibility or scope modifiers - anywhere that could be an attribute will be parsed as one, not as a statement, comment, or whatever else, so some code changes meaning, and other code becomes a syntax error. Regards, -- Rowan Tommins [IMSoP]

« previous php.internals (#111497) next »