How to Setup VSCode for PHP

September 20, 2019

by Yunus Shaikh

In this article, I will list the most useful plugins for VScode if you are a PHP developer. Firstly you should know that there are many PHP extensions available on the VS Code Marketplace which will make VSCode great for PHP Developers. You get features like syntax highlighting and bracket matching, IntelliSense (code completion), and snippets out of the box and you can add more functionality through community-created VS Code extensions.


LET’S GET STARTED

1 – PHP Intelephense by Ben Mewburn


Here is the first and most important plugin. PHP code intelligence for Visual Studio Code. Intelephense is a high-performance PHP language server packed full of essential features for productive PHP development.


This plugin has a premium package however these are a list of free features
  • Fast camel/underscore case code completion (IntelliSense). Offering detailed suggestions for the document, workspace, and built-in symbols and keywords. Automatic addition of use declarations.
  • Detailed signature (parameter) help for the document, workspace, and built-in constructors, methods, and functions.
  • Rapid workspace wide goes to definition support.
  • Workspace wide finds all references.
  • Fast camel/underscore case workspace symbol search.
  • Full document symbol search that also powers breadcrumbs and outline UI.
  • Multiple diagnostics for open files via an error-tolerant parser and powerful static analysis engine.
  • Lossless PSR-12 compatible document/range formatting. Formats combined HTML/PHP/JS/CSS files too.
  • HTML request forwarding to HTML language servers for complete HTML/JS/CSS/PHP code intelligence.
  • Detailed hover with links to official PHP documentation.
  • The smart highlight of references and keywords.
  • Reads PHPStorm metadata for improved type analysis and suggestions.


2 – PHP Namespace Resolver by Mehedi Hassan


PHP Namespace Resolver can import and expand your class. In addition, You can also sort your imported classes by line length or in alphabetical order. In addition, you can use commands to perform operations

Search these commands by the title on command palette.
[
    {
        "title": "Import Class",
        "command": "namespaceResolver.import"
    },
    {
        "title": "Import All Classes",
        "command": "namespaceResolver.importAll"
    },
    {
        "title": "Expand Class",
        "command": "namespaceResolver.expand"
    },
    {
        "title": "Sort Imports",
        "command": "namespaceResolver.sort"
    },
    {
        "title": "Highlight Not Imported Classes",
        "command": "namespaceResolver.highlightNotImported"
    },
    {
        "title": "Highlight Not Used Classes",
        "command": "namespaceResolver.highlightNotUsed"
    },
    {
        "title": "Generate namespace for this file",
        "command": "namespaceResolver.generateNamespace"
    }
]


3 – PHP DocBlocker by Neil Brayfield

We now have a set of unit tests and some full coverage on the parsing of signatures as well as continuous integration. This should ensure the extension remains stable as development progresses. In addition to this here is the list of features


Here are the list of features that plugin offers
  • Completion snippet after /** above a class, function, class property
  • Continuation of DocBlock when pressing enter when in a DocBlock
  • Completion of DocBlock tags such as @param@return@throws
  • Inferring of param and return types from signatures
  • Configuration of template for each type of docblock completion


4 – PHP import checker by Matheus Marabesi


php-import-checker helps you know when a given class is imported but not used, after that providing an easy way to keep your code clean and organized.Highlight every unused class that is imported with use
For example if there is an image subfolder under your extension project workspace:


VSCode check import plugin

VSCode check import plugin



5 – PHP Debug by Felix Becker


Here are the list of features that plugin offers
  • Line breakpoints
  • Conditional breakpoints
  • Function breakpoints
  • Step over, step in, step out
  • Break on entry
  • Breaking on uncaught exceptions and errors / warnings / notices
  • Multiple, parallel requests
  • Stack traces, scope variables, superglobals, user defined constants
  • Arrays & objects (including classname, private and static properties)
  • Debug console
  • Watches
  • Run as CLI
  • Run without debugging


6 – PHP-CS-Fixer by higoka


Last but not least. Just by saving your file PHP-CS-Fixer takes care of the code formatting for you. for instance check below image


VSCode CSFixer

VSCode CSFixer


Here is the an article about Intelephense Premium plugin