Skip to content
CODE THE PIXEL
Tools & Software

Formatting PHP in VSCode Using Prettier and PHP Intelephense

Asyraf Wahi Anuar 2 min read

Learn how to set up Visual Studio Code (VSCode) for automatic PHP file formatting using the Prettier and PHP Intelephense extensions. This step-by-step tutorial will help you maintain a clean and organised codebase, enhancing your PHP development experience.

Tech stack

  • PHP

Visual Studio Code (VSCode) is a popular code editor renowned for its versatility and numerous extensions that enhance the coding experience. Among these, the Prettier extension stands out for its ability to format code consistently across various languages, making it a favourite among developers. However, when it comes to formatting PHP files, many users encounter challenges, as Prettier does not natively support PHP formatting. This limitation can be frustrating, especially for those looking to maintain a clean and organised codebase in PHP.

In this tutorial, I will guide you through the steps to effectively set up your VS Code environment to automatically format PHP files using Prettier in conjunction with the PHP Intelephense extension. By following this guide, you'll be able to streamline your PHP development process and ensure your code looks sharp and professional. Let’s dive in and unlock the full potential of code formatting in VSCode!

  1. Install and enable the Prettier Extension in VS Code

  2. Set as default formatter in VS Code settings:

a) File - Preferences - Settings / Shortcut: CTRL + ,
b) Search: Formatter
c) Editor: Default Formatter select: Prettier - Code Formatter

  1. Install and enable the PHP Intelephense

  2. CTRL + Shift + P then search for "open user settings (JSON)" and insert the following parameter:

PHP
{
... //other config
  "[php]": {
    "editor.formatOnSave": true,
    "editor.defaultFormatter": "bmewburn.vscode-intelephense-client"
  },
  "editor.linkedEditing": true
...
}

All files ending with the .php extension will be formatted using the PHP Intelephense extension. Make sure to securely save the settings.json file to preserve these configurations for future use.

Did this tutorial help?

0 readers found this helpful

Comments

No comments yet. Questions about this tutorial are welcome here: the answer helps the next reader too.

Leave a comment

Markdown works: `code`, ``` blocks, **bold**, links.

First comments are reviewed before they appear.

CakePHP

Using Bahasa Melayu Table Names in CakePHP

Learn how to use Bahasa Melayu table names like "pengguna" in CakePHP while following the framework’s naming conventions. Includes tips for using the Bake tool and avoiding pluralization issues.

5 min read

Tools & Software

Boost Your Productivity with Emmet in VS Code

Emmet is a markup and stylesheet abbreviation tool that allows developers to type shorthand syntax and expand it into full-fledged HTML or CSS code. It's a lifesaver for front-end developers, eliminating the need to manually type out repetitive tags and structures.

7 min read