Php_codesniffer: Failed opening 'PHP/CodeSniffer/autoload.php' for inclusion (include_path='.:')

Created on 4 May 2017  路  16Comments  路  Source: squizlabs/PHP_CodeSniffer

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.

Most helpful comment

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.

All 16 comments

@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

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 the Fix the include_path errors step of the guide. If you have, then the php.ini that PHP is using is not the one that you've modified. Run php -i and look near the top for the loaded config files to see which one to use.

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.

Good to hear. Thanks a lot for getting back to me.

I am sorry to bother, but I still quite confused about the problem. How did you solve the problem finally?

@StevenGAO95 I ran php -i which will give you data about your local php configuration, including which php.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 for include_path in that file, which was commented out, and added include_path = "/usr/local/pear/share/pear".

While I add include_path in my php.ini, it was not solve the problem.
I solve this problem only do this in my pear path:

ln -s share/pear/PHP/ PHP

When i did this and i get this error Failed to fetch http://in.archive.ubuntu.com/ubuntu/pool/universe/p/php-codesniffer/php-codesniffer_2.5.1-2ubuntu1_all.deb Hash Sum mismatch

@adnanlimdiwala I don't maintain any OS packages, so I can't help you with that error.

for me, pear location was /usr/share/pear in arch linux. include_path = "/usr/share/pear" in php.ini worked.

@ethancfchen that worked for me! Thank you!

@0xcrypto I'm on Antergos and this worked for me too.

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.ini

This assumes you are using native php which came with high sierra.

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.ini

This assumes you are using native php which came with high sierra.

This almost worked for me, but the 'pear config-get php_dir' was "hard-coded" on php.ini :/

So I got the Pear path running $pear config-get php_dir and ran your command with my "PEAR PATH", something like this:

$ echo 'include_path = ".:/Users/[my-user]/pear/share/pear"' | sudo tee -a /etc/php.ini

and now worked, thanks :)

In MacOS I could fix it by this line (by specifying version):
include_path = ".:/usr/local/share/[email protected]"

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.ini

This assumes you are using native php which came with high sierra.

The command is missing the backticks, this worked for me on Mac OS Catalina:

echo 'include_path = ".:'`pear config-get php_dir`'"' | sudo tee -a /etc/php.ini
Was this page helpful?
0 / 5 - 0 ratings