AppDividend
Latest Code Tutorials

How To Use PHP In Visual Studio Code

159

Get real time updates directly on you device, subscribe now.

How To Use PHP In Visual Studio Code is today’s leading topic. Visual Studio Code is the great editor for PHP and other language development. You get almost all the features like syntax highlighting, bracket matching, PHP IntelliSense, and snippets out of the box and you can create or add more functionality through community-created Visual Studio Code extensions. No developer enjoys the debugging a web applications. But we all know that we need to use quality software debugging because it is the crucial aspect of development. While the .Net and Java developers often have their language-specific IDEs that contain full debugging support, PHP developers may sometimes feel left out. Sure, there are quite some commercial applications like phpStorm that can help with debugging PHP code. But these business applications are usually very expensive and operating system dependent. Luckily there are a few open source code editors out there that will give PHP developers the same debugging experience without the use of an expensive IDEs and VS Code is one of them.

If you are new to VSCode, then check out my how to install visual studio code on macThat guide will help you to set up the VSCode in your Mac.

Want to learn to code, gain a new skill and get a new job. Check out this amazing program

How To Use PHP In Visual Studio Code

By default, Visual Studio Code comes with the PHP Support, but you can also install the PHP language extensions available on VS Code Marketplace. You can search for the PHP extensions from within the  VS Code in the Extensions view (⇧⌘X) then you can select the extensions using drop-down list by typing php. But first, check your PHP version using the following command.

php -v

 

How To Use PHP In Visual Studio Code

I have PHP version 7.2.11 and if you have something like 5.6.* or 7.0.* or 7.1.* then it is good to update your PHP version. I have installed PHP using homebrew, so I can update the PHP version using the following command. This PHP version upgrade guide is for MAC and not for Windows.

brew upgrade php

If you are using MAMP or XAMPP, then you need to update that software bundle as well to get the latest PHP version.

PHP extensions for VSCode

PHPIntelliSense and PHP Debug are most IMP extensions for PHP Development Environment. But there are more extensions that you can use based on your project flow or your style to write the code. Extensions will help you to fast your workflow and reduce your code repetition and also provide code completion.

 

PHP extensions for VSCode

PHP IntelliSense

To install and use the PHP Intellisense, you need at least PHP 7 installed on your machine. You can either add it to your PATH or set the  php.executablePath setting. If you are facing duplication then disabling VS Code’s built-in PHP IntelliSense by setting php.suggest.basic to falseYou can add the php executable path inside user settings.

Earn a Tech Degree and get the skills like Frontend Development or Javascript Development that can help you to launch a career. Checkout this amazing program
"php.executablePath": "/usr/local/Cellar/php/7.2.11/bin/php"

Please find your PHP Executable and do not copy above code if you have different PHP version and the way you have installed PHP previously because PHP’s path will be changed on your machine as well. For example, if you are using MAMP or XAMPP, then the php path is different. I have used Homebrew so, I can write the above path.

Features Of Intellisense

  1. Code Completion
  2. Workspace symbol search
  3. Signature Help
  4. Find all references
  5. Go to definition

PHP Debug

Install the extension: Press F1 and type ext install php-debug.

This extension is the debug adapter between the VS Code and XDebug by Derick Rethan. XDebug is the PHP extension (a .so file on Linux and a .dll on Windows) that needs to be installed on your server.

Features Of PHP Debug

  1. Line breakpoints.
  2. Conditional Breakpoints.
  3. Function breakpoints.
  4. Step over, step in, step out.
  5. Break on entry.
  6. Breaking on uncaught exceptions and errors/ warnings/notices.
  7. Multiple, parallel requests.
  8. Stack traces, scope variables, superglobals, user defined constants.
  9. Arrays & objects (including class name, private and static properties).
  10. Debug console.
  11. Watches.
  12. Run as CLI.
  13. Run without debugging.

PHP Code Linting

VS Code uses the official PHP linter (php -l) for PHP language. It allows VS Code to stay current with PHP linter improvements.

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"). The default is on save.

Finally, How To Use PHP In Visual Studio Code article is over.

Leave A Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.