The expression expected in PhpStorm when using PHP variables in JavaScript functions

When I use php variable variables for JavaScript variables, I get the "expected expression" from PhpStorm.

I cannot change the file extension to something.js.php, because I already use the blade server template, so it should beblade.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>
Run codeHide result

I added a sample html page for more details. In phpstrom

var myJavascriptVar = <?php echo $myVar; ?>;
Run codeHide result

and

 var myJavascriptSecondVar = {{$myVar;}};
Run codeHide result
Operators

express the expected error.

+4
source share
1 answer

This is a bug (incomplete processing between languages) in PhpStorm.

(//), . - .

+2

Source: https://habr.com/ru/post/1649898/


All Articles