Skip to content

PSR12 ruleset: report property names prefixed with an underscore as an error - #1487

Merged
jrfnl merged 1 commit into
PHPCSStandards:4.xfrom
syedusmanali:syedusmanali/1426-psr12-property-underscore-error
Aug 21, 2026
Merged

PSR12 ruleset: report property names prefixed with an underscore as an error#1487
jrfnl merged 1 commit into
PHPCSStandards:4.xfrom
syedusmanali:syedusmanali/1426-psr12-property-underscore-error

Conversation

@syedusmanali

Copy link
Copy Markdown
Contributor

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 error and 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 cs and composer test both pass.

Fixes #1426

…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 jrfnl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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!

@jrfnl
jrfnl merged commit 7f47350 into PHPCSStandards:4.x Aug 21, 2026
55 checks passed
@jrfnl

jrfnl commented Aug 21, 2026

Copy link
Copy Markdown
Member

@syedusmanali Just one note: next time, please use the PR template.

@syedusmanali
syedusmanali deleted the syedusmanali/1426-psr12-property-underscore-error branch August 22, 2026 09:07
@syedusmanali

Copy link
Copy Markdown
Contributor Author

@syedusmanali Just one note: next time, please use the PR template.

will keep that in mind

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PSR12: should PSR2.Classes.PropertyDeclaration.Underscore be reported as an error?

2 participants