sirbrillig / phpcs-variable-analysis

Find undefined and unused variables with the PHP Codesniffer static analysis tool.
Other
136 stars 14 forks source link

Assignment to array element reference does not count as a write #319

Open sirbrillig opened 7 months ago

sirbrillig commented 7 months ago

static function dotToMultiArray(
    array $array
): array {
    $multi = [];
    foreach($array as $key => $value){
        $level = &$multi;
        foreach(explode(".", $key) as $node)
            $level = &$level[$node];
        $level = $value;
    }
    return $multi;
}

This marks $level as unused but the third assignment actually changes the referenced variable.