Search code examples
javascriptphpphpstorm

Expression expected in PhpStorm when using php variables in JavaScript functions


When I am using changing php variables to JavaScript variables, I am getting "expression expected" error from PhpStorm.

I cannot change the extension of the file to something.js.php because I am already using blade template so it should be blade.php

This is the first example

This is the second example

<!DOCTYPE html>
<html>
<body>
<?php $myVar = 5;?>

<script type="text/javascript">
    var myJavascriptVar = <?php echo $myVar; ?>;
    var myJavascriptSecondVar = {{$myVar;}};
    alert(myJavascriptVar + myJavascriptSecondVar);
</script>
</body>
</html>

I have added a sample html page for more clarification. In PhpStrom the

var myJavascriptVar = <?php echo $myVar; ?>;

and

 var myJavascriptSecondVar = {{$myVar;}};

statements gives expression expected error.


Solution

  • That's a bug (incomplete inter-language handling) in PhpStorm.

    Watch those tickets (star/vote/comment) to get notified on any progress. Right now they are not assigned to any specific future versions.