There are quite a few options out there when it comes to developing with PHP, each has their own strengths and weaknesses. Here I’ll be discussing my preferred toolkit that I use day-to-day.
As mentioned Code has a rather meagre offering with regard to PHP integration. That changes quite a bit when some key extensions are thrown into the mix however.
Extensions of note are;
- PHP Tools for VS Code ← My daily driver
As best I can tell, this is the only option for debugging PHP within VS Code. Although PHP Tools for VS Code technically supports XDebug PHP debugging, it does so using the sources of this extension (and has garned some critisim for not attributing the author nor including its license).
At the time of writing its not perfect but gets the job done. There are a few bugs unfortunately but even with that in mind its an essential tool for productive PHP development.
There isn't anything to really compare it too at present, but if it came down to PHP Tools for VS Code vs. XDebug, I would always go with XDebug since its the most likely to be properly supported and regularly updated for a number of reasons.
There are a handful of code completion extensions around for PHP, some targetted at specific libraries, others more general. Of the ones that I have used Intelliphense "just works" and has a resonably comprehensive type inference system.
It doesn't have any external dependencies, resource consumption during code analysis is reasonable, and in my experience has never made an incorrect inference regarding a type instead preferring to drop down to
mixed which works really well when hitting parts of PHP it does not yet understand sufficiently.
This is an awesome extension, I can't recommend it enough.
PHP Tools for VS Code
Alright, so first up this is a paid extension and the trial is in my experience not quite long enough to make a purchase decision with. Its also a bit of a grab bag of functionality in that it does a lot of different things but they don't necessarily tie together as well as they potentially could and as such I'll be discussing it feature-by-feature.
It presents itself as a professional solution, and for the most part lives up to the expectations. It also isn't dependent on the PHP runtime to work, leaving this as a solid no-dependencies option.
Despite some nasty performance edge caess, the intellisense support offered by PHP Tools is fantastic. It isn't always as intuitive as Intelliphense, but it does a much better job at detecting and reporting problems which all have error codes which can be ignored should the need arise.
One of the areas where PHP Tools excells is supporting new functionality. At the time of writing PHP 7.4 isn't yet out, and features like class member types are already supported on release builds, complete with PHP compatiblity warnings.
On the note of PHP compatibility warnings however, this appears to be resolved exclusively from the local PHP runtime which limits the usefulness when containerisation solutions like Docker as in use. Its a shame as this is one area where dedicated PHP IDEs like PHP Storm excel, but I guess there are PHP Codesniffer based alternatives (provided you can figure out how to integrate it right).
¯\(ツ)/¯ Sadly I sparingly have the chance to write nor run unit tests on my main projects. Hopefully in time, at which point I'll update this section.
Under the hood, this is just the community XDebug plugin repackaged. Nothing much else to say.
Odds and Ends
There are a few odds and ends that this extension brings. Among them is variable renaming (which works roughly 50% of the time) and go to definition (works 99% of the time).
Compared to other ecosystems profiling isn't particularly well integrated into most PHP workflows, in part as it requires setting up XDebug which isn't always the easiest tool to get up and running. Despite this however XDebug is one of my core profiling tools, at least once paired with a tool like WinCache so I can actually make sense of the profiler output.
Exploring the call graph recorded by XDebug can take some getting used to, but provides a wealth of information. Statistics like the number of times a function has been invoked and their execution times, and the sum of those times are available which works great for shining a spotlight on areas where performance gains might be made.
There is a rather notable problem with XDebug profiling however, while it is running certain operations will take longer which can result in some red herrings if care is not taken. In these situations implanting manual timers to benchmark (without XDebug running) suspect slow code is recommended.