PSR12 ruleset: report property names prefixed with an underscore as an error - #1487
Merged
jrfnl merged 1 commit intoAug 21, 2026
Conversation
…n error PSR-12 section 4.3 states that property names MUST NOT be prefixed with a single underscore to indicate protected or private visibility, using the same normative strength as section 4.4 does for method names. The PSR12 standard already promotes the PSR2.Methods.MethodDeclaration.Underscore message to an error with "must not" wording, but the equivalent PSR2.Classes.PropertyDeclaration.Underscore message was still inherited from PSR2 as a warning with "should not" wording. This promotes the property message to an error under PSR12 and aligns the message text with the PSR-12 wording, mirroring the existing override for the method message. The PSR2 standard itself is unaffected and continues to report both cases as warnings. Fixes PHPCSStandards#1426
jrfnl
approved these changes
Aug 21, 2026
jrfnl
left a comment
Member
There was a problem hiding this comment.
@syedusmanali Thank you for creating this PR and your willingness to contribute to PHP_CodeSniffer.
I've (manually) verified the change and all looks good. Thank you!
Member
|
@syedusmanali Just one note: next time, please use the PR template. |
syedusmanali
deleted the
syedusmanali/1426-psr12-property-underscore-error
branch
August 22, 2026 09:07
Contributor
Author
will keep that in mind |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PSR-12 section 4.3 uses MUST NOT for underscore-prefixed property names, the same wording section 4.4 uses for methods. The PSR12 standard already promotes the method message (
PSR2.Methods.MethodDeclaration.Underscore) to an error, but the property message (PSR2.Classes.PropertyDeclaration.Underscore) was still inherited from PSR2 as a warning.This adds the same ruleset-level override for the property message: type
errorand the message text updated to "must not", mirroring the existing method override.PSR2 itself is unchanged and still reports both cases as warnings.
Verified against a small fixture with an underscore-prefixed property and method: PSR12 now reports both as errors with the "must not" wording, PSR2 output is unchanged.
composer csandcomposer testboth pass.Fixes #1426