Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require attributes be placed below docblocks #8

Closed
lpd-au opened this issue Apr 29, 2022 · 5 comments · Fixed by #26
Closed

Require attributes be placed below docblocks #8

lpd-au opened this issue Apr 29, 2022 · 5 comments · Fixed by #26
Labels
core enhancement New feature or request

Comments

@lpd-au
Copy link
Contributor

lpd-au commented Apr 29, 2022

To the best of my recollection in all of the code I've encountered, despite functioning correctly in either order, attributes are placed between any docblock and the target they apply to (class, method, etc). If you were to instead place attributes above the docblock, you'd encounter a nasty bug in any static analyser that relies on nikic's parser (eg phpstan): nikic/PHP-Parser#762. In my opinion, this PER should require a consistent order of docblock first, then attributes and finally the node.

@Crell
Copy link
Collaborator

Crell commented Apr 29, 2022

I've run into this parser issue as well. At its root it's a PHP-Parser bug, but even that aside it's the sort of arbitrary thing worth trying to standardize.

@TomasVotruba
Copy link

TomasVotruba commented Jun 10, 2022

I came across similar issue few times too.
This order makes sense as docblock is just a comment above any PHP code. Does not matter if attribute or any other stmt:

/** ... */
public $property;

/** ... */
#[Attribute]

Also, maybe we could help to automate it with @rectorphp :) rectorphp/rector#7225

@KorvinSzanto
Copy link
Contributor

KorvinSzanto commented Jul 17, 2022

Just linking these together:
#26 does require attributes come after any comments

@snake-py
Copy link

Also it seems that the guide is not really clear how many lines of code are allowed between the attribute and the class.

#[Attribute]
class Test 
or 

#[Attribute]

class Test 

@Crell
Copy link
Collaborator

Crell commented Oct 12, 2022

The PR in #26 makes it clear that no blank line is permitted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants