PHPstorm shows "Error" in Code - i don't think so...

Hi,

i have this:

<a href="javascript:killDatensatz('<?php echo $kundendatensatz['arbeitseinheit_ID'] ?>')">peng</a>

or

<a href="javascript:killDatensatz('<?= $kundendatensatz['arbeitseinheit_ID'] ?>')">peng</a>

PHPstorm underlines the both red parts with red and says "Expecting new line or semicolon"

But I think, it's correct code - or is it my fault?


cu

3 comments
Comment actions Permalink

Hi Jorg,

It's the way how IDE works -- the JavaScript language is automatically injected into this part (you should see light green background if using default theme):

killDatensatz('<?php echo $kundendatensatz['arbeitseinheit_ID'] ?>')

Purely from JavaScript point of view it is of course invalid code, as it treats second quote character ( $kundendatensatz['arbeitseinhei ) as closing one. It's all because when additional language gets injected, the whole text there is treated as that language (in your particular case even PHP code is treated as JavaScript).

If you uninject the injected language from this fragment, you will see that it works properly once again.

In any case -- to keep things as is while still having it working -- replace inner single quotes to double: ["arbeitseinheit_ID"]

0
Comment actions Permalink

Hi Andriy,

thank you. But I think it should work - because I use <?= or <?php - so the IDE should know, that here PHP starts.

So it should be this Javascriptcode:

killDatensatz('')


i call a javascript-function with an (maybe empty) parameter.

In other IDEs thats no problem

Is it possible to switch of the "errorwarnings" from PHPstorm for some positions? So that I will not see an "errorwarning" for only this code-part?

I have some parts in my code, where PHPstorm shows an Error, but there is no Error. But I see this files in the "Projectwindow" red underlined.

cu

0
Comment actions Permalink
But I think it should work - because I use <?= or <?php - so the IDE should know, that here PHP starts.

If you think that it is an incorrect behavior then feel free to file new ticket to the Issue Tracker. I cannot tell for sure if current behavior is a bug or if it works as intended.

Is it possible to switch of the "errorwarnings" from PHPstorm for some positions? So that I will not see an "errorwarning" for only this code-part?

If it is possible, then such action will be available via Alt+Enter (fix tooltip). In this particular case -- no (as far as I can tell). You can only disable such inspection for the whole file:

  • Create custom scope (Settings | Scopes) that will include such file(s)
  • Settings | Inspections -- find the inspection in question, right click and choose "Add Scope" -- now you can turn off this particular inspection for those files.

In other IDEs thats no problem

I have not used other IDEs for a while (for web development only using PhpStorm and Dreamweaver CS5). Out of curiosity, what IDE can do this -- have language injected (so code completion, syntax, code analyzer works) and still have PHP properly recognized inside such fragment?

0

Please sign in to leave a comment.