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

preg_match() error after downgrade from PHP 7.3 to 7.2 #2884

Closed
yani-tactics opened this issue Feb 28, 2020 · 4 comments
Closed

preg_match() error after downgrade from PHP 7.3 to 7.2 #2884

yani-tactics opened this issue Feb 28, 2020 · 4 comments

Comments

@yani-tactics
Copy link

I'm getting an error while running phpcbf (using a VSCode extension) on Windows 10 x64.

I installed the package globally using composer with PHP 7.3. There were no problems. Then I downgraded PHP in my PATH to 7.2, after which I removed and re-installed the global package. Both removed and newly installed versions were 3.5.4.

Now whenever I save a file, which runs the fixer. I get these errors:

Warning: preg_match(): Compilation failed: \k is not followed by a braced, angle-bracketed, or quoted name at offset 14 in C:\Users\Yani\AppData\Roaming\Composer\vendor\squizlabs\php_codesniffer\src\Filters\Filter.php on line 272

Call Stack:
    0.2067     401792   1. {main}() C:\Users\Yani\AppData\Roaming\Composer\vendor\squizlabs\php_codesniffer\bin\phpcbf:0
    0.2124     709888   2. PHP_CodeSniffer\Runner->runPHPCBF() C:\Users\Yani\AppData\Roaming\Composer\vendor\squizlabs\php_codesniffer\bin\phpcbf:18
    0.3424    4771512   3. PHP_CodeSniffer\Runner->run() C:\Users\Yani\AppData\Roaming\Composer\vendor\squizlabs\php_codesniffer\src\Runner.php:200
    0.3526    5301008   4. PHP_CodeSniffer\Files\FileList->addFile() C:\Users\Yani\AppData\Roaming\Composer\vendor\squizlabs\php_codesniffer\src\Runner.php:370
    0.3532    5329112   5. PHP_CodeSniffer\Filters\Filter->rewind() C:\Users\Yani\AppData\Roaming\Composer\vendor\squizlabs\php_codesniffer\src\Files\FileList.php:127
    0.3532    5329112   6. PHP_CodeSniffer\Filters\Filter->accept() C:\Users\Yani\AppData\Roaming\Composer\vendor\squizlabs\php_codesniffer\src\Files\FileList.php:127
    0.3534    5329256   7. PHP_CodeSniffer\Filters\Filter->shouldIgnorePath() C:\Users\Yani\AppData\Roaming\Composer\vendor\squizlabs\php_codesniffer\src\Filters\Filter.php:115
    0.3534    5330136   8. preg_match() C:\Users\Yani\AppData\Roaming\Composer\vendor\squizlabs\php_codesniffer\src\Filters\Filter.php:272
@gsherwood
Copy link
Member

The \k that it is complaining about is not something that's directly part of PHP_CodeSniffer. It's probably a filter string being passed into PHP_CodeSniffer by the plugin. Maybe it is passing an invalid regular expression, or one that PHP_CodeSniffer does not support. I don't know where there would be a difference between PHP 7.2 and 7.3 though.

I don't build or maintain any IDE plugins, so this is likely something you'd need to report to whatever project does. But if you can replicate an issue using the phpcs command directly, please post the results here.

@gsherwood gsherwood added this to Idea Bank in PHPCS v3 Development via automation Mar 2, 2020
@gsherwood gsherwood moved this from Idea Bank to Track in PHPCS v3 Development Mar 2, 2020
@jrfnl
Copy link
Contributor

jrfnl commented Mar 2, 2020

I don't know where there would be a difference between PHP 7.2 and 7.3 though.

PHP 7.3 switched to PCRE 2.0, so there is definitely a difference there. The short of it is that the regex engine has become stricter/less tolerant about incorrect regexes.

@yani-tactics
Copy link
Author

In another project:

Warning: preg_match(): Compilation failed: PCRE does not support \L, \l, \N{name}, \U, or \u at offset 38 in C:\Users\Yani\AppData\Roaming\Composer\vendor\squizlabs\php_codesniffer\src\Filters\Filter.php on line 272

Call Stack:
    0.2075     402032   1. {main}() C:\Users\Yani\AppData\Roaming\Composer\vendor\squizlabs\php_codesniffer\bin\phpcbf:0
    0.2207     710128   2. PHP_CodeSniffer\Runner->runPHPCBF() C:\Users\Yani\AppData\Roaming\Composer\vendor\squizlabs\php_codesniffer\bin\phpcbf:18
    0.3679    4771392   3. PHP_CodeSniffer\Runner->run() C:\Users\Yani\AppData\Roaming\Composer\vendor\squizlabs\php_codesniffer\src\Runner.php:200
    0.3885    5318744   4. PHP_CodeSniffer\Files\FileList->addFile() C:\Users\Yani\AppData\Roaming\Composer\vendor\squizlabs\php_codesniffer\src\Runner.php:370
    0.3893    5346848   5. PHP_CodeSniffer\Filters\Filter->rewind() C:\Users\Yani\AppData\Roaming\Composer\vendor\squizlabs\php_codesniffer\src\Files\FileList.php:127
    0.3893    5346848   6. PHP_CodeSniffer\Filters\Filter->accept() C:\Users\Yani\AppData\Roaming\Composer\vendor\squizlabs\php_codesniffer\src\Files\FileList.php:127
    0.3895    5347024   7. PHP_CodeSniffer\Filters\Filter->shouldIgnorePath() C:\Users\Yani\AppData\Roaming\Composer\vendor\squizlabs\php_codesniffer\src\Filters\Filter.php:115
    0.3896    5347936   8. preg_match() C:\Users\Yani\AppData\Roaming\Composer\vendor\squizlabs\php_codesniffer\src\Filters\Filter.php:272

I will try and debug the plugin.

@yani-tactics
Copy link
Author

I don't have the time to figure out how to find the executed command. But it seems forcing PSR2 standards when no phpcs.xml file is found fixes my issue with the vscode extension. I have cross-posted this issue at the extension: wongjn/vscode-php-sniffer#32

It might be interesting to know why this breaks.

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

No branches or pull requests

3 participants