Highlight.js: PHP degraded in 9.x?

Created on 9 Apr 2016  Â·  8Comments  Â·  Source: highlightjs/highlight.js

I went to update my site from 8.4 to 9.3 and noticed that PHP highlight lost details. Seems to no longer recognize variables (maybe more?).

See screenshot before/after:

highlight-js-php-comparison

Example, screenshot was taken from, live here http://www.rarst.net/code/dependency-injection/ (still on 8.4 hadn't pushed 9.3 up).

Most helpful comment

Looked for something in older post and PHP highlight is nearly gone in some snippets.

highlight-js-while

Without variables, properties, methods, functions... Not much of highlight, it's nearly plain text.

All 8 comments

Dropping highlighting of regular variables was deliberate, this is a design decision. We should bring back $this though as it is special…

I've fixed $this and have gone ahead and fixed the whole issue, as it is unlikely we revert to highlighting plain user-defined variables.

Why so?.. Variable seems to be pretty staple thing to highlight.

Loosely related — I also find it very nifty in IDE when variables and passed arguments are treated separately for highlight, easy to distinguish what is passed into function and what is created inside of it.

The reason is two-fold.

First, we just want to be consistent across languages. Most highlighters don't highlight local variables in other languages simply because they're not syntactically distinguishable. In PHP (and, say, Perl) they're easy to highlight because of the $ sign. But "because we can" is not reason enough.

Second, one of our design guidelines is to keep the bulk of code plain and only highlight things that are semantically significant, and highlighting them will add to code readability (all of this highly subjective and fuzzy, of course). Thus, we don't highlight many things that others do: UPPERCASE_CONSTANTS, CamelCaseNames, .method_calls().

I also find it very nifty in IDE when variables and passed arguments are treated separately for highlight

This we can't do because a highlighter has to work at the syntactic level, it can't keep track of the meaning of identifiers, for example.

Fair enough, thanks for the fix on $this at least. :)

You're welcome! :)

Looked for something in older post and PHP highlight is nearly gone in some snippets.

highlight-js-while

Without variables, properties, methods, functions... Not much of highlight, it's nearly plain text.

It actually does look good to me, honestly. I understand it's subjective but that's how it is.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

OrbintSoft picture OrbintSoft  Â·  8Comments

starikovs picture starikovs  Â·  8Comments

niche4u picture niche4u  Â·  5Comments

gskinner picture gskinner  Â·  4Comments

zhouxy666 picture zhouxy666  Â·  3Comments