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/ValidFunctionName: fix uninitialized string offset error #2028

Conversation

jrfnl
Copy link
Contributor

@jrfnl jrfnl commented May 25, 2018

When a function name would contain more than one subsequent underscore, the explode() call will create entries containing an empty string in the $nameBits array.

The proposed fix will remove those empty entries before testing each $bit.
(array_filter() called without callback will remove everything which after juggling would evaluate to false).

Note: The resulting suggested $newName for the function will no longer contain a double underscore either.

If it would be desired to allow the double underscore, the alternative would be to change the if ($bit{0} !== strtoupper($bit{0})) condition to if ($bit !== '' && $bit{0} !== strtoupper($bit{0})). This would also require an adjustment in the inner loop which creates the new package name.

Includes unit test.

Fixes #2027

When a function name would contain more than one subsequent underscore, the `explode()` call will create entries containing an empty string in the `$nameBits` array.

The proposed fix will remove those empty entries before testing each `$bit`.
([`array_filter()` called without callback](http://php.net/manual/en/function.array-filter.php#example-6090) will remove everything which after juggling would evaluate to `false`).

**Note:** The resulting suggested `$newName` for the function will no longer contain a double underscore either.

If it would be desired to allow the double underscore, the alternative would be to change the `if ($bit{0} !== strtoupper($bit{0}))` condition to `if ($bit !== '' && $bit{0} !== strtoupper($bit{0}))`. This would also require an adjustment in the inner loop which creates the new package name.

Includes unit test.

Fixes 2027
@gsherwood
Copy link
Member

If it would be desired to allow the double underscore

I had a look through the PEAR coding standard again underscores are only used for namespacing. Function names aren't actually supposed to be defined using underscores instead of camelCase, although the sniff would have to check directory names to see if the underscore were truely being used for namespacing.

So I don't think any additional changes would be needed for this PR.

@gsherwood gsherwood added this to the 3.3.0 milestone Jun 1, 2018
@gsherwood gsherwood merged commit a285842 into squizlabs:master Jun 1, 2018
gsherwood added a commit that referenced this pull request Jun 1, 2018
@gsherwood
Copy link
Member

Thanks a lot for fixing this

@jrfnl jrfnl deleted the feature/2027-pear-validfunctionname-fix-uninitialized-offset-error branch June 1, 2018 13:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PEAR.NamingConventions.ValidFunctionName error when function name includes double underscore
2 participants