Skip to content

Squiz.Strings.ConcatenationSpacing fix creates syntax error when joining a number to a string #1252

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

Closed
gseric opened this issue Dec 28, 2016 · 2 comments

Comments

@gseric
Copy link

gseric commented Dec 28, 2016

This fixer generates invalid PHP code in some cases. E.g.:

// Original PHP code:
echo 1 . 'test';

// After fix (syntax error!!!):
echo 1.'test';

// Should be:
echo (1).'test';

PHP reports the following error:

Parse error: syntax error, unexpected ''test'' (T_CONSTANT_ENCAPSED_STRING), expecting ',' or ';'

PHP treats dot as decimal separator instead of concat operator if used directly after number.

PHP_CodeSniffer 2.7.1

@gsherwood gsherwood changed the title Squiz.Strings.ConcatenationSpacing fix results with invalid PHP code Squiz.Strings.ConcatenationSpacing fix creates syntax error when joining a number to a string Jan 3, 2017
gsherwood added a commit that referenced this issue Jan 3, 2017
…ax error when joining a number to a string
@gsherwood
Copy link
Member

Thanks for the report.

The fixer now puts parenthesis around LNUMBER and DNUMBER tokens before and after string concats without spaces. It doesn't technically need to do DNUMBER before a string concat, but I don't think it hurts.

@gseric
Copy link
Author

gseric commented Jan 4, 2017

Thank you!

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

No branches or pull requests

2 participants