7

I am having a problem in PHPStorm where it won't highlight PHP code (but will intellisense it) inside a .php file when it's mixed with HTML code.

Screenshot (click to enlarge):

Screenshot

If I invalidate cache/restart, it will, for a few seconds, show the correct highlighting. However, after it "calculates", it will return to not highlighting it.

Is there a setting for this? Or is it just a plain bug?

I have read about language injections, but this does not seem like the place for it since it's a .php file already and PHP is not on the list of injectable languages.

Relevant code:

<?php
$works = "yes";
?>

<html>
<body>

<script>
    var shouldStillWorkAfterThis = true;
</script>

<?php
$works = "yes";
?>

<table>
    <tr>
        <td><?php $works = "yes"; ?></td>
    </tr>
</table>

<!-- lets try split syntax -->
<?php
if ($works) {
    ?>
    <table>
        <tr>
            <td><?= $works ?></td>
        </tr>
    </table>
    <?php $thisShouldToo = true; ?>
<?php } ?>

<!-- lets break it -->
<div id="someclass">
    <header>
        <div class="someotherclass">
            <div class="andanextraclass">
                <!-- include a file-->
                <?php include('somefile.php');?>
                <?php
                    $anythingHereIsNowBroken = true;
                ?>
            </div>
        </div>
    </header>
</div>

</body>
</html>

Language Injections Settings:

Language Injections

I am using PhpStorm 8.0.3 on MacOSX 10.9.5.

9
  • Try reducing some of the HTML above the PHP code and see if you can still reproduce the issue. Then, post all the code in the file so that we can try reproducing it. See How to create a Minimal, Complete, and Verifiable example. Commented May 30, 2015 at 8:58
  • Screenshot of your Settings (Preferences on Mac) | Editor | Language Injections please. Commented May 30, 2015 at 9:13
  • Here you go : puu.sh/i5JQd/458618c38e.png Commented May 30, 2015 at 9:14
  • Here is a test file : pastebin.com/Z3hMY4ur and related screenshot : puu.sh/i5JZO/b1532e72c6.png Commented May 30, 2015 at 9:18
  • Please update your question with all the new information that you have. You can edit your question by clicking on "edit" under the question. Commented May 30, 2015 at 9:26

1 Answer 1

14

Based on your screenshot of Settings (Preferences on Mac) | Editor | Language Injections.

Please delete 3rd language injection rule from the bottom (the one for "div" -- that has "IDE" in Scope column).

That rule injects HTML into div tag which tells IDE to treat all other code (even PHP) inside such tag as HTML/plain text.

Sign up to request clarification or add additional context in comments.

2 Comments

Thats exactly the problem. Thank you :) Here is how it looks afterwards: puu.sh/i5L8D/d8cffe4471.png
Perfect solution. After more than year of this answer it solved my problem. I am using PHPStorm 2016.3 in Windows.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.