Skip to content

False positive for function names starting with triple underscore #1240

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

Merged

Conversation

jrfnl
Copy link
Contributor

@jrfnl jrfnl commented Dec 14, 2016

Function and method names starting with a double underscore are reserved by PHP itself for magic functions/methods.

A triple underscore function name prefix, however, should not trigger this error. (I'm not saying it's a good idea, but it's out there in userland code)

Fixed in the two non-proprietary standards which have checks for double underscored function/method names.
Includes additional unit tests for all four sniffs.

This PR does not cover similar checks in the proprietary PEAR and Squiz standards.

Fixes PHPCompatibility/PHPCompatibility#297

Any function and method names starting with a double underscore are reserved by PHP itself for magic functions/methods.

A triple underscore function name prefix, however, should not trigger an error. (not saying it's a good idea, but it's out there in userland code)

Fixed in the two non-proprietary standards which have checks for double underscored function/method names.
Includes additional unit tests for all four sniffs.

This PR does not cover similar checks in the proprietary PEAR and Squiz standards.
@aik099
Copy link
Contributor

aik099 commented Dec 14, 2016

Your code also does cover cases when 3+ (not just exactly 3) underscores are used.

@jrfnl
Copy link
Contributor Author

jrfnl commented Dec 14, 2016

Your code also does cover cases when 3+ (not just exactly 3) underscores are used.

Correct, it does.

@gsherwood gsherwood changed the title Fix false positive for function names starting with triple underscore. False positive for function names starting with triple underscore Dec 15, 2016
@gsherwood gsherwood merged commit f578621 into squizlabs:master Dec 15, 2016
gsherwood added a commit that referenced this pull request Dec 15, 2016
@gsherwood
Copy link
Member

Thanks for the fix. I also ended up fixing it in the PEAR and Squiz standards because they were trying to do the same thing.

@jrfnl jrfnl deleted the fix/namingconventions-false-positive branch December 15, 2016 00:35
@jrfnl
Copy link
Contributor Author

jrfnl commented Dec 15, 2016

@gsherwood You're welcome ;-)

@jrfnl
Copy link
Contributor Author

jrfnl commented Dec 15, 2016

P.S.: I did originally also add it for the PEAR and Squiz standards (locally), but ended up removing it as the unit tests I added for it were triggering the CamelCase rules for those sniffs, so no matter what, the function name would end up not being acceptable.

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.

“Function name “__” is discouraged”
3 participants