How to install php intellisense in visual studio code

In this video we will install Visual Studio Code, install the PHP IntelliSense extension and create a simple PHP file in Visual Studio Code.

The video starts with showing you how to download and install Visual Studio Code.

The second part is about how to install the PHP IntelliSense in Visual Studio Code.

And, finally, we create a folder in XAMPP localhost and create a simple test example index.php file.

This video is made for those looking to install Visual Studio Code, install PHP IntelliSense and/or if you are looking to find how to create and load a simple PHP file in Visual Studio Code.

If you have any question or comment, leave in the comment section below.

How to install php intellisense in visual studio code

We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies.

VS code is a tool mostly used by front-end developers. It’s highly optimized to work with JavaScript and TypeScript, featuring smart autocompletion, auto-imports, refactors, and other goodies.

Although no match to IDEs like PHPStorm, Visual Studio Code can be customized to have better support when working PHP.

The most important thing you can do

The most important thing to do if you want to work with PHP in VS code is to disable the default language server and install PHP Intelephense.

This is literally 90% of the job and it’s super easy.

  1. Within Visual Studio Code, go to the “Extensions” tab and search PHP.
  2. Uninstall PHP IntelliSense (it will be installed by default)
  3. Install PHP Intelephense.

Note: I'm not being payed by intelephense to write this!

You will want to disable the default PHP suggestions integrated into VS code. To acheive this, add this line to your user settings:

"php.suggest.basic": false,

(To open your settings, open the console with Cmd+Shift+P and search the key “Preferences: Open user settings (JSON)”)

After changing this, your PHP code will start behaving a little big “smarter”.

If you’re done this, you have it. 90% of the functions you wanted from PHPStorm are already in VS code.

Here are some of those features you now have:

  • Highlight syntax, type errors and other static analysis tools
  • Autodetect installed libraries and bring them in suggestions based on your composer.json
  • Detect unused imports, unused private functions or unused variables.
  • Automatically creates phpdoc annotations with configurable format, and reads them when writting method or function calls.

Some other extensions you might want to install

Here are some other extensions that might be handy to cover that missing 10% of features that are not bundled with Intelephense.

  1. PHP Dockblocker enhances the capabilities of Intelephense regarding the creation of phpdoc type comments.
  2. PHP Namespace Resolver Allows to automatically import a class using Ctrl+Opt+I and automatically expand the class (a.k.a.: import it inline, to get \Path\To\Class) using Ctrl+Opt+E. If there are name conflicts, a prompt shows all the options.
  3. laravel-blade is an extension to highlight syntax in Blade files. Laravel goto view allows to cmd+click in @import()s and other blade tags.

Extensions for speficic tasks

There are a lot of extensions to add some little extra functionalities you might need. Like this extension to add getter and setter methods, and this one or this one to generate constructor properties.

Third party integrations

Integrations with Docker and various SQL database flavours are also available as plug-ins. A personal favourite is GitLens, that complements the Git support of the editor with some cool, advanced functions (at the expense of a little performance loss).

Conclusion

There are a lot more extensions in the market and a million more posts that curate them, so I will leave this one kinda open and just drop a link to the VS code marketplace for you to take a look 😉.

VS code is not an IDE, but a code editor. Yet, by using extensions we can make it look and behave kind of like an IDE. It’s no match against PHPStorm in it’s advanced features, but it can provide the most used features with some simple customizations.

Have you heard about the Visual Studio Code for the Web? It's the code editor running in your browser, allowing to work with your local files, files on your GitHub repositories, or files on Azure. Anywhere.

In case of the PHP language, the VS Code for the Web is perfect for quick edits on small projects, due to its limitations,


PHP Tools for Visual Studio Code is now available on the VS Code for the Web. All the editor features can be used in this browser-based development environment.

Installation

There are currently a few VSCode on the Web applications, including https://vscode.dev or https://github.dev.

Navigate to the one of those, and your on-line workspace will open.You can either open a folder, a remote codespace, or single files. To enable PHP support in your .php files, switch to Extensions, and look for "php tools". Click Install.

How to install php intellisense in visual studio code

Open a PHP file to start working. To confirm you have successfully activated the extension, see the VSCode's Output Window, PHP (Language Server) tab. Or hover a mouse over something - you should see a net tooltip as we are used to from VS Code or Visual Studio:

How to install php intellisense in visual studio code

Features

There is a lot of features included; the entire code editor, IntelliSense, code formatting, errors analysis, type analysis, PHPDoc generator, multilingual PHP manual, navigating to phar files, navigating to symbols in PHP manual, outlining, code actions, signature help, auto-importing use, semantic highlighting, inline editing, rename refactoring, ... and more.

IntelliSense

How to install php intellisense in visual studio code

The code completion including tool tips and all the available symbol information is included.

Code Actions

How to install php intellisense in visual studio code

The editor provides also code actions - generating constructors, implementing interface methods, getters and setters, sorting uses, and others. See the documentation for more examples.

PHPDoc Generator

PHPDoc is generated seamlessly. Just type /** above a declaration. Although, it might be necessary to enable it in File / Preferences / Settings - where editor.formatOnType must be set to true.

How to install php intellisense in visual studio code

Upon enabling the formatOnType setting, doc comments are nicely generated. This includes the available information from the syntax and the type analysis, eventually also with thrown exception information.

How to install php intellisense in visual studio code

Problems Analysis

The code editor also analyses the entire workspace for errors. The code is checked in the same way as in Visual Studio or Visual Studio Code. Based on syntax, semantics, and the type analysis, you get code underlined, errors listed in Problems window, including tooltips providing additional details.

How to install php intellisense in visual studio code

Limitations

The limitations are described at the VS Code's documentation page: https://code.visualstudio.com/docs/editor/vscode-web#_limitations.

Since the editor won't process all the files in your workspace, the IntelliSense might not be complete. In the result, code lenses with useful commands are not enabled since they would not provide complete results, code problems do not mention unknown classes and functions, tooltips might not provide the complete information, and Laravel facades might not provide complete IntelliSense either.

Additionally, the extension is unable to debug PHP code even though, it would be technically possible.

Test Explorer and PHPUnit integration is not included either.

It's important to remember, that the first time the extension is used, it might take a few seconds while the browser is downloading the extension file. It may be about 10 MB or more of data.

How do I add IntelliSense code to Visual Studio?

You can trigger IntelliSense in any editor window by typing Ctrl+Space or by typing a trigger character (such as the dot character (.) in JavaScript). Tip: The suggestions widget supports CamelCase filtering, meaning you can type the letters which are upper cased in a method name to limit the suggestions.

How do I add php code to Visual Studio?

You can search for PHP extensions from within VS Code in the Extensions view (Ctrl+Shift+X) then filter the extensions dropdown list by typing 'php'.

How do I show IntelliSense in Visual Studio?

The suggestion list of Basic completion appears when you press the default Visual Studio IntelliSense shortcut Ctrl+Space . If necessary, you can always return to the Visual Studio's native's IntelliSense. To do so, select Visual Studio on the Environment | IntelliSense | General page of ReSharper options ( Alt+R, O ).

How do I Preview php code in Visual Studio?

Click the button Open In Browser on StatusBar..
In the editor, right click on the file and click in context menu Open PHP/HTML/JS In Browser..
Use keybindings Shift + F6 to open more faster (can be changed in menu File -> Preferences -> Keyboard Shortcuts ).