PhpStorm structural searching to find a self-assignment in a foreach loop

Deadly 提交于 2021-02-07 10:35:56

问题


I have noticed a pattern among some of my team's developers where we will do a self-assignment of an array in a foreach loop, and I am looking for the proper search parameters to pass into PhpStorm's structural search to match the first workflow, but not the second in the following example:

public function example()
{
    $array = [];
    foreach ($array as $a) {
       $array[$a] = 1; //Match this one
    }

    $someOtherVariable = [];
    foreach($array as $ab) {
        $someOtherVariable[] = 2; //Don't match this one
    }
}

The basic structural search foreach($c$){$c$} matches them both, and I cannot figure out if there is a filter to apply to the variable $c$ such that the interior variable is detected to be the same as the inherited loop variable.

来源:https://stackoverflow.com/questions/62805674/phpstorm-structural-searching-to-find-a-self-assignment-in-a-foreach-loop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!