PHP_CodeSniffer: Failed opening 'PHP/CodeSniffer/autoload.php' for inclusion (include_path='.:')
I previously had PHPCS running on OS X by following the steps found at https://viastudio.com/configure-php-codesniffer-for-mac-os-x/. I got a new laptop and installed by following those steps, but now when I attempt to run receive the following error messages:
Warning: include_once(PHP/CodeSniffer/autoload.php): failed to open stream: No such file or directory in /usr/local/bin/phpcs on line 14
Warning: include_once(): Failed opening 'PHP/CodeSniffer/autoload.php' for inclusion (include_path='.:') in /usr/local/bin/phpcs on line 14
Fatal error: Class 'PHP_CodeSniffer\Runner' not found in /usr/local/bin/phpcs on line 17
My other laptop was also running OS X Sierra, so I don’t think that’s the issue, but not positive.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 16 (3 by maintainers)
Thanks @gsherwood! I had followed the fix include_path errors step, but as you suggested it looks like I was modifying the wrong php.ini file. Adding
include_path = "/usr/local/pear/share/pear"
to/etc/php.ini
did the trick.@StevenGAO95 I ran
php -i
which will give you data about your local php configuration, including whichphp.ini
file is being loaded. For me it returned/etc/php.ini
, which didn’t actually exist, so I had to copy/etc/php.ini.default
to/etc/php.ini
and then searched forinclude_path
in that file, which was commented out, and addedinclude_path = "/usr/local/pear/share/pear"
.While I add
include_path
in myphp.ini
, it was not solve the problem. I solve this problem only do this in mypear
path:@lstanard the below worked for me: ln -s ~/.composer/vendor/squizlabs/php_codesniffer/bin/phpcs /usr/local/bin/phpcs ln -s ~/.composer/vendor/squizlabs/php_codesniffer/bin/phpcbf /usr/local/bin/phpcbf
For anyone having errors with phpcs autoloader on mac os x high sierra, do in terminal:
echo ‘include_path = “.:‘
pear config-get php_dir
’”’ | sudo tee -a /etc/php.iniThis assumes you are using native php which came with high sierra.
In MacOS I could fix it by this line (by specifying version):
include_path = ".:/usr/local/share/pear@7.2"
I do all PHPCS development on macOS Sierra, so there is no problem with the OS that would stop you running it.
It looks like you don’t have your
include_path
set properly in PHP (the error indicates you don’t have one set at all). You’ll need to make sure you’ve done theFix the include_path errors
step of the guide. If you have, then thephp.ini
that PHP is using is not the one that you’ve modified. Runphp -i
and look near the top for the loaded config files to see which one to use.This almost worked for me, but the
'pear config-get php_dir'
was “hard-coded” onphp.ini
😕So I got the Pear path running
$pear config-get php_dir
and ran your command with my “PEAR PATH”, something like this:and now worked, thanks 😃
@0xcrypto I’m on Antergos and this worked for me too.