skip to Main Content

I found something similar to this while doing a code review, and I don’t see what is wrong with the code (shown as a syntax error by PhpStorm). The problem is using PHP short echo tags in an HTML attribute. PhpStorm doesn’t seem to have a problem with the usage in the label’s for attribute, or the input’s id attribute, but indicates there is an error in the input’s name attribute. Here is a simple way to replicate.

Filename: trash.phtml

<?php
/** ...*/
function getId(): string
{
    return '0';
}
?>
<label for="bundle_me[<?= getId(); ?>]"></label>
<input type="hidden"
       id="bundle_me[<?= getId(); ?>]"
       name="bundle_me[<?= getId(); ?>]"/>

This is PhpStorm 2021.1.4 running on a Linux VM.
PHP version 7.4

Screenshot of PhpStorm's code detection having a problem with the name attribute.

2

Answers


  1. Looking at your screenshot — the name attribute value has different (light green) background… which tells that you have somehow injected another language there.

    1. Settings/Preferences | Editor | Language Injections
    2. Look at all entries there where Scope column has "IDE" or "Project" values.
    3. Locate and disable unexpected rule (most likely will be HTML or XML + name and/or input mentioned)
    4. If all good — you can now delete that wrong rule.
      • If not sure: post that screen with IDE & Project scope rows.
    5. If still nothing — could be some plugin (AFAIK bundled Angular plugin has similar kind of issues…)
    Login or Signup to reply.
  2. It’s a bug in the Angular plugin: https://youtrack.jetbrains.com/issue/WEB-39052
    Has to be fixed by the WebStorm team. In the meanwhile, you can disable the plugin if you are not using Angular.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search