The files in question are .php and not unusually they mostly consist of html and javascript with a little bit of php at the top. I've noticed that PHPStorm doesn't highlight javascript syntax errors in php files. If I put the exact same code in a .html file it highlights errors as it should. I've tried setting the php files in question as HTML in settings > template data language but it doesn't help. I could set all the pages to have .html exts (as this the only thing that works) but then I lose my php formatting and syntax checking. I'm using PHPStorm 8.0.2. This seems like a bug. How do I fix this?
1 Answer
Save the file as .php and then specify JavaScript as a secondary language by going to Settings >> Template Data Languages
Syntax highlighting of PHP inside JavaScript (and other languages)
6 Comments
hedgehog90
I don't want it to be recognized as a javascript file though. It's essentially an html file containing script tags and a tiny bit of php. I set it in the Template Data Languages to Javscript and it doesnt account for all the html. It should automatically do syntax highighting in script tags within a PHP file, because it's default is to assume it's HTML. The fact it does this for .HTML files suggests this is a bug. I don't understand how I'm seemingly the only person with this problem, I've searched online for hours and asked on the Jetbrains forum as well.
Brock Amhurst
I think you're misunderstanding my answer. The link I posted shows the opposite of what I suggested but the principle is the same... if you're using multiple languages, set the secondary languages as such in the settings. Btw, you cannot have PHP inside an html file... anytime you have PHP, it must be inside a PHP file and enclosed in <?php ... ?> tags. All your html must be outside the PHP tags or echoed. Please check to ensure you're implementing your PHP properly.
hedgehog90
My php is properly enclosed in <?php ... ?>. Read the OP and actually test it and tell me if you get the same thing. I've tried setting my secondary language to Javascript, HTML or PHP, and creating new file types like the link states, none of it works. If I set it to any one of these it assumes the entire file is in that language and I get incorrect highlighting and colours. I've read elsewhere that a php file with no altered settings should act exactly like a HTML file in PHPStorm. If that's the case then this has to be a bug because it never highlights improper syntax.
hedgehog90
I submitted it as a bug, please tell me if you get the same results as I do when writing bad syntax in a php file : youtrack.jetbrains.com/issue/WI-26214
Brock Amhurst
Your php file needs to start with <?php ?> ... In the example you posted, both on here and on the bug report you submitted, you do not have those php tags. This is the critical difference between putting the script in a plain HTML file and putting it in a PHP file, you must have those <?php ?> tags
|
<script type="text/javascript"> if (true) } { </script>in an otherwise empty php file, I get no highlighting. If I have the exact same line in an otherwise empty html file, I get 2 red lines.