VS Code extensions for PHP development

Graphic representation of the docking of PHP with Visual Studio Code

These VS Code extensions for PHP development are a starting point to configure your IDE. From here you can experiment and configure your Visual Studio Code work environment for PHP projects.

I do not like to add a lot of extensions in VS Code to avoid performance issues in my workstation, that’s why I always try to keep things simple and the less convoluted possible. I recommend to configure Visual Studio Code by projects and spend some time preparing each work environment.

PHP Intelephense

This is the best-ranked extension at this moment if we consider the ratio stars/downloads.

PHP Intelephense offers excellent support with autocomplete PHP expressions. Gives you shortcuts to functions definitions fast and intuitively. It also offers a popover on hover with information about the functions extracted from the official documentation, (PHP, WordPress, Drupal, Laravel), or the comments in the function’s definition. Besides it grays out unused imports and vars.

One piece of advice, once installed PHP Intelephense is a good idea to disable the native support of VS Code for PHP suggestions. That way the list with suggestions will come only from the extension and it will be less crowded and you will avoid unnecessary duplicates.

Print screen with VS Code options for PHP
View of Visual Studio Code options for PHP

PHP Code Sniffer

PHP CS checks your PHP code to make it comply with the norms of your standard of choice, it uses Pear coding standard by default. Keep this in mind if you are working in different PHP projects because you will need to change your PHP standard in the settings.

Before installing the extension PHP Code Sniffer you need to install phpcs globally. Chances are that you already have Composer .


composer global require "squizlabs/php_codesniffer=*"     
          

After that step, you are free to install the actual extension in Visual Studio Code. You can check in the terminal which standards you have already installed:


phpcs -i 
          

In my case I added WordPress later. Here you can find guide to add the WordPress standard to PHP CS.

PHP Coding Standards Fixer

PHP CS Fixer modifies your PHP code accordingly to the norms of your standard: PSR-2, WordPress, Symfony, etc. You are also free to create a standard for a specific project and share it with your team.

You can configure PHP Coding Standards Fixer to modernize or optimize your code according to your needs. Of course this extension works closely with your linter and it is excellent combined with PHP Code Sniffer. But please double-check that you are using the same PHP standard in both extensions to avoid a mess.

Print screen of VS Code options for PHP CS and PHP CS Fixer, both extensions are using the WordPress standard for PHP
VS Code options for PHP CS and PHP CS Fixer, both extensions are using the WordPress standard for PHP

Besides these basics extensions you will need probably one extension with snippets for your framework or vanilla PHP. For Laravel, you can use Laravel Snippets by Winnie Lin Drupal devs can count with Drupal 8 Snippets. And for those in the WordPress universe there is WordPress Snippets.

Probably at some point, you will need to debug your PHP code and PHP Debug for VS Code is an excellent choice. This extension is a debug adapter between VS Code and XDebug by Derick Rethan. You will need to install XDebug first and then configure PHP to make use of XDebug.

I hope these extensions can help out to set up your PHP workspace with Microsoft Visual Studio Code and increase your productivity. At the very least you will gain a cleaner code to share or review in the future.