Using Heredoc Syntax for Improved Syntax Highlighting

If you find yourself writing PHP code containing other languages (JS snippets, SQL queries, etc.), you can use PHP’s Heredoc syntax for improved syntax highlighting, at least in VS Code.

Basically, Heredoc syntax uses <<< to note the beginning of a string, followed by an identifier. Everything until the next instance of that identifier is treated as a string.

Here are examples:

You may not get autocompletion and other IDE features, but at least it’s easier to read.

What you choose for the identifier does impact the syntax highlighting…for example, if I had used SQL instead of JS in the example above, the code would have been highlighted differently. I suspect this is a feature of ProseMirror, though I haven’t dug into it to find out for sure.