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

PEAR.NamingConventions.ValidFunctionName error when function name includes double underscore #2027

Closed
jthayne opened this issue May 25, 2018 · 3 comments · Fixed by #2028
Closed
Milestone

Comments

@jthayne
Copy link

jthayne commented May 25, 2018

When running PHPCS on an existing codebase, the following error occurred:

An error occurred during processing; checking has been aborted. The error message was: Uninitialized string offset: 0 in /usr/share/pear/PHP/CodeSniffer/src/Standards/PEAR/Sniffs/NamingConventions/ValidFunctionNameSniff.php on line 239 (Internal.Exception)

This occurred on the following function name: send_system_email__to_user

After removing the double underscore, the error goes away.

Example code

<?php

function send_system_email__to_user($body, $recipient){
        echo 'test';
}

I am using version 3.2.3 of PHP_CodeSniffer and PHP v 5.6.36

@jrfnl
Copy link
Contributor

jrfnl commented May 25, 2018

Thanks for reporting this with all the info needed. I've confirmed the bug. PR to fix this upcoming.

@jrfnl
Copy link
Contributor

jrfnl commented May 25, 2018

Testing of PR #2028 would be appreciated.

@gsherwood gsherwood added this to Selected for Development (v3) in PHPCS v3 Development May 29, 2018
@gsherwood gsherwood modified the milestone: 3.3.0 Jun 1, 2018
@gsherwood gsherwood changed the title PHP Error when function name includes double underscore in the middle of the name PEAR.NamingConventions.ValidFunctionName error when function name includes double underscore Jun 1, 2018
gsherwood added a commit that referenced this issue Jun 1, 2018
@gsherwood
Copy link
Member

This was fixed by PR #2028. You now get the following error messages for the sample code:

Function name "send_system_email__to_user" is prefixed with a package name but does not begin with a capital letter
Function name "send_system_email__to_user" is invalid; consider "Send_System_Email_To_user" instead

The PEAR standard only allows underscores for namespacing, which is why it assumes each word is a directory and needs to begin with a capital. If you don't want to use camelCase for function names, you should disable this specific sniff.

Thanks for the bug report.

@gsherwood gsherwood moved this from Selected for Development (v3) to Ready for Release in PHPCS v3 Development Jun 1, 2018
@gsherwood gsherwood removed this from Ready for Release in PHPCS v3 Development Jun 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants