On 12 August 2020 19:03:02 BST, Jakob Givoni <ja...@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]

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to