Microsoft’s Visual Studio Code is utterly competent with the PHP language. It’s something that shocked me personally when it was released as I didn’t expect it to come prepared for PHP developers. But yep, it is a strong development environment for PHP, and of course, there are plenty of extensions to be used with it.

In this article, I will go through the best available extensions that can be installed with your version of VSCode. With this list of essential extensions, you can configure your Visual Studio Code IDE into a wizardry-code-environment.

First and foremost is Intellisense, I don’t think I could live without this one. Intellisense will offer to autocomplete on native PHP functions while you type. This extension by Felix Becker is super-responsive too, meaning unlike some other IDE’s, it always instantly gives you options within your autocomplete drop down.

Although VSCode comes with a Debug widget fresh out the box, it doesn’t necessarily mean it works with all programming languages instantly. PHP is no exception, and you must download the framework for debugging to work with Visual Studio Codes debug module.

I wrote an article on how to set up debugging PHP with VS Code a while back. The tutorial instructs how to configure for code-level-simulation debugging and live-browser debugging. This is another feature that I couldn’t live without, and I’m almost sure that it’s the same for you!

What on earth is DocBlocker I hear you ask, well, if you are asking that question, essentially a DocBlock is a comment block. See the following code snippet for example –

/** * * * */

This extension makes it very quick to append this block to your code, wherever you may need it. What’s also great is that it comes packed with comment tags like @author, @method, @group and @return. You can quickly get access to these tags with their respective snippets by pressing the @ symbol and choosing from the drop-down list. Here is another example of the DocBlocker with some tags.

class myClass { /** * @method mixed myMethod() * @author CodeWall <info@codewall.co.uk> * @param mixed $myParam * */ public myMethod($myParam) { } }

So, if you’re a big fan of comments, this way of commenting code is well worth putting in to practice. It’s not only helpful, but the style is known industry-wide.

Because us coders love to type super-turbo-fingered-fast, we can’t always guarantee that our code layout is correctly tabbed and indented. With the above extension, you don’t have to worry, with a quick tap of CTRL + ALT + F, the extension will magically format the PHP into a pretty formatted file. You can also configure the extension to run its formatting every time you save the file too.

A quick note with this extension though, is that you must have the path to the PHP engine specified to work properly. Whether that be on a server on your local machine, it must be specified in the VSCode extension settings.

Another convenient extension is the Getter & Setter package, I’ll give you half a millisecond to work out what it does. Yep, you guessed it, this extension quickly adds ‘get and set’ functions to your code. It’s as simple as right-clicking on the variable you want getters and setters for and executing the extensions helper. This extension will turbo-charge your object-oriented PHP development.

See the following code for an example of what it adds to your file for you.

/** * Get the value of myVar */ public function getMyVar() { return $this->myVar; } /** * Set the value of myVar * * @return self */ public function setMyVar($myVar) { $this->myVar = $myVar; return $this; }

Just in-case your not aware of what snippets are, they mainly are keywords that you type out and hit return to print out a particular snippet of code to your file. For example, in this snippet pack, if we type ‘c’ and hit return, a full PHP class will be written to your file in an instant. These of course are extremely handy and help speed up development. The above pack has all super-globals and a few class-based snippets too.

If you’ve used PHP Storm before, you’ll already know about these handy snippets, if not, no worries, you know about them now! This pack has shortcuts for loops like, foreach require and include commands and more class-based snippets. Visit the link above for a data-table showing each shortcut and their description.

When using PHP frameworks like Laravel, declaring classes to use at the top of the file becomes widely used. But, over-time, you’re bound to have a cluttered list of classes, and one of them won’t be of required use. This checker extension essentially ‘lints’ those classes that aren’t necessary to your file and highlights them for deletion. Essentially, it’s a cleaning tool for your code and a good one at that.

VSCode doesn’t come fresh out of the box all-singing-all-dancing, and that is why this extension was created. After installing, you will have access to three pre-formatted file type creating functions, namely, class , interface and trait . After selecting either of these as your creation file type, all you have to do is name it, and the file will be created, pre-filled with code, ready to go!

When specifying interface names, the possibility of comma-separating is present, meaning that the code will be pre-filled with these defined names. It’s well worth checking out.

Summary

The listed extensions within this article will give any PHP developer the perfectly equipped IDE for hassle-free development. Visual Studio Code is pretty basic out of the box, but with a little bit of effort, can be precisely what you want it to be. These nine extensions are probably the most important, but there are plenty more where they came from. The VS market place loads with extensions that you can browse through all-day-long.

If you have experience with some other extensions, be sure to leave them in the comments for other developers to discover too!

The Author: Dan Englishby

Post navigation