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

3.0.0RC1 PHAR does not work with PEAR standard #1167

Closed
sebastianbergmann opened this issue Sep 21, 2016 · 6 comments
Closed

3.0.0RC1 PHAR does not work with PEAR standard #1167

sebastianbergmann opened this issue Sep 21, 2016 · 6 comments

Comments

@sebastianbergmann
Copy link
Contributor

$ php-56 --version
PHP 5.6.26-dev (cli) (built: Aug 22 2016 18:36:51) 
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
    with Xdebug v2.5.0-dev, Copyright (c) 2002-2016, by Derick Rethans
$ php-70 --version
PHP 7.0.11-dev (cli) (built: Aug 20 2016 08:33:54) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
    with Xdebug v2.5.0-dev, Copyright (c) 2002-2016, by Derick Rethans
$ wget https://github.com/squizlabs/PHP_CodeSniffer/releases/download/3.0.0RC1/phpcs.phar
$ php-56 phpcs.phar

Fatal error: Cannot redeclare class PHP_CodeSniffer\Standards\PEAR\Sniffs\Commenting\FileCommentSniff in phar:///home/sb/phpcs.phar/src/Standards/PEAR/Sniffs/Commenting/FileCommentSniff.php on line 2

Call Stack:
    0.0031     439840   1. {main}() /home/sb/phpcs.phar:0
    0.0044     605176   2. PHP_CodeSniffer\Runner->runPHPCS() /home/sb/phpcs.phar:6
    0.0097    1074472   3. PHP_CodeSniffer\Runner->init() phar:///home/sb/phpcs.phar/src/Runner.php:2
    0.0121    1376416   4. PHP_CodeSniffer\Ruleset->__construct() phar:///home/sb/phpcs.phar/src/Runner.php:2
    0.0138    1392984   5. PHP_CodeSniffer\Ruleset->registerSniffs() phar:///home/sb/phpcs.phar/src/Ruleset.php:2
    0.0155    1565152   6. PHP_CodeSniffer\Autoload::loadFile() phar:///home/sb/phpcs.phar/src/Ruleset.php:2
    0.0160    1716192   7. include('phar:///home/sb/phpcs.phar/src/Standards/PEAR/Sniffs/Commenting/FileCommentSniff.php') phar:///home/sb/phpcs.phar/autoload.php:2
$ php-70 phpcs.phar 

Fatal error: Cannot declare class PHP_CodeSniffer\Standards\PEAR\Sniffs\Commenting\FileCommentSniff, because the name is already in use in phar:///home/sb/phpcs.phar/src/Standards/PEAR/Sniffs/Commenting/FileCommentSniff.php on line 2

Call Stack:
    0.0034     576328   1. {main}() /home/sb/phpcs.phar:0
    0.0045     684240   2. PHP_CodeSniffer\Runner->runPHPCS() /home/sb/phpcs.phar:6
    0.0103     966632   3. PHP_CodeSniffer\Runner->init() phar:///home/sb/phpcs.phar/src/Runner.php:2
    0.0126    1156344   4. PHP_CodeSniffer\Ruleset->__construct() phar:///home/sb/phpcs.phar/src/Runner.php:2
    0.0146    1166344   5. PHP_CodeSniffer\Ruleset->registerSniffs() phar:///home/sb/phpcs.phar/src/Ruleset.php:2
    0.0160    1290656   6. PHP_CodeSniffer\Autoload::loadFile() phar:///home/sb/phpcs.phar/src/Ruleset.php:2
    0.0166    1378240   7. include('phar:///home/sb/phpcs.phar/src/Standards/PEAR/Sniffs/Commenting/FileCommentSniff.php') phar:///home/sb/phpcs.phar/autoload.php:2
@gsherwood gsherwood changed the title 3.0.0RC1 PHAR does not work with PHP 5.6 / PHP 7.0 3.0.0RC1 PHAR does not work with PEAR standard Sep 21, 2016
@gsherwood
Copy link
Member

Problem was caused by code relying on realpath() to remove relative references, which it wont do in a phar. Changed code to not use relative paths in this case.

Only happened in the PEAR standard as ClassCommentSniff autoloads FileCommentSniff before the ruleset has a chance to include it manually. It seems the order of all other sniffs works out to have the ruleset load the file directly before any autoloading takes place.

Thanks for the bug report.

@birkett
Copy link

birkett commented Jan 28, 2017

Still seeing this with RC2 - exactly the same.

@gsherwood
Copy link
Member

@birkett Are you sure you have RC2? I've downloaded a fresh copy and tested it. It's still working fine.

@birkett
Copy link

birkett commented Jan 30, 2017

Yes - 3.0.0RC2.
Using the PHAR, on Windows, with PHP 7.1.1. All PHP related commands and tools are being run under MSYS (Git Bash).

@gsherwood
Copy link
Member

I've managed to replicate the issue now. I get:

Fatal error: Cannot declare class 
PHP_CodeSniffer\Standards\PEAR\Sniffs\Commenting\FileCommentSniff,
because the name is already in use in 
phar://D:/PHP_CodeSniffer/phpcs.phar/src/Standards/PEAR/Sniffs/Commenting/FileCommentSniff.php
on line 2

@gsherwood
Copy link
Member

I've found the new problem - inconsistent directory separators were causing the file to be included twice by the autoloader. This will be released in RC3.

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

3 participants