dongpi0658 2018-02-12 13:08
浏览 88
已采纳

PhpStorm - 如何强制处理字符串?

How can I force to be handle just as a string and not be interpreted by the IDE as something that it is not?

Granted the following string is rather unusual and gets identified as SQL by the IDE.

'SELECT {$selectors} FROM `{$table}`{$where}{$order}{$limit}{$offset}'

As you probably guessed by now, the placeholders are seen as invalid SQL code, and give me a slew of error in the IDE.

Already attempted to "fix" those issues via @noinspection, but there are multiple warnings and errors detected in that one line of code, that it is not feasible to suppress those "issues" one by one.

Another drawback is that some errors require me to disable some really useful inspections and I really don't want that.

So, is there a way just force PhpStorm to treat that one string as an actual string and not, in this case, SQL?

  • 写回答

2条回答 默认 最新

  • dsa5211314 2018-02-12 13:26
    关注

    You may disable SQL Language Injection into all strings. Downside: it affects whole project (or even ALL projects, considering the fact that it's a built-in rule and therefore it's an IDE-wide setting).

    This can be done at Settings/Preferences | Editor | Language Injections.


    An option just for that string is to forcibly inject Plain Text language by placing /** @lang Text */ just before the string:

    $s2 = /** @lang Text */'SELECT {$selectors} FROM `{$table}`{$where}{$order}{$limit}{$offset}';
    

    See the difference:

    enter image description here

    P.S. Notice the difference between interpolated string (HEREDOC in this case; but the same is for sting using "" as delimiters) vs '' (single quotes/NOWDOC). It still sees it as SQL but shows no warnings (which means that IDE understand that $table is something dynamic). But it could be just my settings -- checking it in my few-years-old Test project...

    enter image description here

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的