Bug: wrong classes for php inside js


When php code is written in a single line inside javascript code it has a wrong class attached (it’s not recognized as php code, but instead the opening bracket is interpreted operator).
This works
<?php // something ?>

This doesn’t work:
<?php // something ?>


What grammar is the file using? What scopes are attached to each of those elements?


It’s a .php file, with the following content:

And this it what it looks like in the inspector:


The // comment, mark everything to the end of line as comment, and thus probably mark the end ?> as comment too.

Does it work better with /* comments such as this */ ?


The comments are not the problem.

The problem is having the opening “<?php" and the closing "?>” in the same line. Regardless of the content:
This causes a problem:
<?php ?>
This Not
<?php ?>


The file extension indicates to Atom what grammar it should use, but you just saying the file extension doesn’t tell us what grammar it’s actually using. If someone wants to try to replicate it, they can’t do that without knowing exactly which package is involved.

I’ve taken a look at it, and it has to do with the first regex in the php.cson file of the language-php package:

'begin': '(^\\s*)(?=<\\?(?![^?]*\\?>))'

A bit of testing on Regex101 reveals that the negative lookahead (?![^?]*\\?>) is the malefactor. I appear to have fixed it by removing that lookahead, but I’m not sure what the lookahead was there for in the first place. To figure that out, I opened an issue to ask about it and will submit a PR if there’s nothing wrong with removing it.

In the mean time, you can download my fork of the package and disable the built-in one.


I replaced the language-php for yours but didn’t fixed my problem. It still happens when i open/close a php tag in the same line inside a tag… :confused:


When you go to Settings -> Packages, does it list language-php as a community package?


PHP inside JavaScript tags is broken in Atom 1.12.x (in fact, it never worked, but now the problem is just more pronounced). We are not planning to fix this as doing so would cause a JavaScript highlighting regression. Everything will be properly fixed in Atom 1.13, which is currently in beta.