dongpi0658 2018-02-12 05: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 05: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 爱快路由器端口更改错误导致无法访问
  • ¥20 安装catkin时遇到了如下问题请问该如何解决呢
  • ¥15 VAE模型如何输出结果
  • ¥15 编译python程序为pyd文件报错:{"source code string cannot contain null bytes"
  • ¥20 关于#r语言#的问题:广义加行模型拟合曲线后如何求拐点
  • ¥15 fluent设置了自动保存后,会有几个时间点不保存
  • ¥20 激光照射到四象线探测器,通过液晶屏显示X、Y值
  • ¥50 数据库开发问题求解答
  • ¥15 安装anaconda时报错
  • ¥15 小程序有个导出到插件方式,我是在分包下引入的插件,这个export的路径对吗,我看官方文档上写的是相对路径
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部