Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

dennisprudlo's avatar

VSCode Syntax Highlighting for PHP 8.1

Hey guys, I wanted to update my dev environment for PHP 8.1. The only thing I didn't get to work properly is the syntax highlighting. Intelephense correctly shows errors, it's really just the syntax highlighting by VSCode.

New keywords such as enum or readonly are in the same color and style as constant names. And after inspecting the tokens and scope VSCode actually shows that the token name for these keywords is constant. When I style this token myself so they have the same style as for instance class, interface or trait it works, but as you may guessed after that all my constants have the same style as the storage.type token.

Has anyone an idea on how to style these new keywords? I can't be the only one who wants to have them styled properly :D

0 likes
9 replies
fylzero's avatar

@dennisprudlo Did you look at the VS Code setting for Intelephense -> Environment: PHP Version and update that to 8.1.0 ?

This fixed enums for me.

dennisprudlo's avatar

@fylzero Yup, is set to 8.1, had to do it so Intelephense shows no syntax errors, but its still not highlighted. Did this change fixed the syntax highlighting or just syntax errors?

fylzero's avatar

@dennisprudlo For me the enum highlighting has the Enum reference in blue, :: in red, words in white, arrow -> in red. It seems highlighted enough/doesn't bother me? Maybe it depends on your theme. Not sure. I'm using Monokai Pro.

dennisprudlo's avatar

@fylzero Well the colors depend on the theme which is used. I'm talking more about the general style (for instance structures are italic in my style, but enums aren't, because they are considered a "constant" in VSCodes tokens. And I mean the actual "enum" keyword not the case name.

Try inspecting the tokens: Open a file with an enum inside, open the command palette, run "Developer: Inspect Editor Tokens and Scopes", then click on the "enum" keyword. In the panel displayed what do you see under "foreground"?

This should make it more clear: https://ibb.co/9YwpHgR

fylzero's avatar

@dennisprudlo

CommentTypeEnum - 15 chars
language - php
standard token type - Other
foreground - #5AD4E6
background - #222222
contrast ratio - 9.09
textmate scopes
    support.class.php
    meta.method-call.php
    meta.class.body.php
    meta.class.php
    source.php
    meta.embedded.block.php
    text.html.php
foreground
    support.class
    { "foreground": "#5AD4E6" }
dennisprudlo's avatar

@fylzero And that's exactly the issue I try to fix :D In my case "enum" is considered as the token constant instead of support.class, storage.type or something similar. Did you click on the Name of the enum or the keyword? "CommentTypeEnum" seems to be the name.

fylzero's avatar

@dennisprudlo I clicked the enum - the part that says "CommentTypeEnum"

Possibly stupid suggestion... did you change the PHP version to 8.1 or 8.1.0? Can't imagine that would matter, but might be worth trying?

dennisprudlo's avatar

@fylzero Yep I tried that, still no luck. But does intelephense do the tokenization? I mean intelephense does recognize the enum as a structure with all autocompletion and docblocks, etc. It's really just the style the tokenization.

What does VSCode say, when you click the "enum" keyword not the name. So literally the word "enum"?

fylzero's avatar

@dennisprudlo If I click enum in the enum class I get:

enum - 4 chars
language - php
standard token type - Other
foreground - #F7F1FF
background - #222222
contrast ratio - 14.38
textmate scopes
    constant.other.php
    source.php
    meta.embedded.block.php
    text.html.php
foreground
    constant.other
    { "foreground": "#F7F1FF" }

Please or to participate in this conversation.