Visual Studio Code is a great editor for PHP development. 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.
Linting
VS Code uses the official PHP linter [php -l
] for PHP language
diagnostics. This allows VS Code to stay current with PHP linter improvements.
Tip: Using XAMPP? Install the full version of PHP in order to obtain the development libraries.
There are three settings to control the PHP linter:
php.validate.enable
: controls whether to enable PHP linting at all. Enabled by default.php.validate.executablePath
: points to the PHP executable on disk. Set this if the PHP executable is not on the system path.php.validate.run
: controls whether the validation is triggered on save [value:"onSave"
] or on type [value:"onType"
]. Default is on save.
To change the PHP settings, open your User or Workspace Settings [⌘, [Windows, Linux Ctrl+,]] and type 'php' to filter the list of available settings.
To set the PHP executable path, select the Edit in settings.json link under PHP > Validate: Executable Path, which will open your user settings.json
file. Add the php.validate.executablePath
setting with the path to your PHP installation:
Windows
{
"php.validate.executablePath": "c:/php/php.exe"
}
Linux and macOS
{
"php.validate.executablePath": "/usr/bin/php"
}
Snippets
Visual Studio Code includes a set of common snippets for PHP. To access these, hit ⌃Space [Windows, Linux Ctrl+Space] to get a context-specific list.
PHP extensions
There are many PHP language extensions available on the VS Code Marketplace and more are being created. You can search for PHP extensions from within VS Code in the Extensions view [⇧⌘X [Windows, Linux Ctrl+Shift+X]] then filter the extensions dropdown list by typing 'php'.
Disable built-in PHP support
To disable the built-in PHP smart completions in favor of suggestions from an installed PHP extension, uncheck PHP > Suggest: Basic, which sets php.suggest.basic
to false in your settings.json
file.
Debugging
PHP debugging with XDebug is supported through a PHP Debug extension. Follow the extension's instructions for configuring XDebug to work with VS Code.
Next steps
Read on to find out about:
- Extension Marketplace - Browse the extensions others have shared
- Debugging - Learn more about VS Code debugging
9/1/2022
Power up your PHP productivity
Photo by Ben Griffiths on UnsplashPHP [recursive acronym for PHP: Hypertext Preprocessor
] is a popular and widely used server-side scripting language that is specially used for web development. It also can be embedded into HTML.
I believe it is hard to find a developer who doesn’t use VSCode. It is one of the most popular IDE out there. Here are 7 VScode extensions which will help you to make the best use of VScode if you are a PHP developer.
1. PHP Tools
This is an all-in-one extension. This extension provides all the needed development configuration for PHP developers like fast code completion, code fixes, code lenses, code generators, debugger, built-in development web server, test explorer, tests debugger, and workspace-wide code analysis. It has an installation of more than 298k.
2. Laravel Snippets
I think Laravel is the most used PHP framework. Larvel is an open-source framework that will help you to build a wide range of custom web applications. This extension will help you to autocomplete Laravel facades. For example: Request::
, Route::
etc. It supports Laravel 5.x-9.x. It has an installation of more than 1M.
3. PHP import checker
This extension provides an easy way to keep your code clean and organized. In a large project, there will be a lot of file imports and sometimes it becomes hard to check which files are used and which are not. This extension will let you know when a given class is imported but not used. You can also customize the color.
4. PHP TDD
TDD [Test-driven development] is the software development process where software requirements are converted to test cases before the software is fully developed and the software is developed by tracking all software development by repeatedly testing the software against all test cases. This development process helps to make the software high performance. This extension will help you to create, run and edit unit tests in your PHP application. It uses PHPUnit under the hood.
5. PHP Form Builder
If you have a project I believe you have a form in it. The form is one of the most used UI component. This extension is for Php Form Builder, a PHP class to build forms in Bootstrap 4, Bootstrap 5, Bulma, Foundation, Material, Tailwind, uiKit, etc.
6. Format HTML in PHP
A large file always needed a formatter. It increases the readability. This extension provides formatting for the HTML code in PHP files. This extension runs just before the save action, which activates any other registered PHP formatting extensions, so you’re free to use one. It has an installation of more than 1M .
7. PHP Namespace Resolver
A namespace is used to contain a PHP code. This extension will help you to import and expand your class. You can also sort your imported classes by line length or in alphabetical order. It has an installation of more than 654k .
That’s all for today. I hope this extension will help to make the development journey easier.
If you know of any other beautiful PHP extension, please share it in the comment. Until we meet again…Cheers!
Want to Connect?If you want to, you can connect with me on Twitter or LinkedIn.