Phpinspectionsea: False positive for value being overwritten immidiately in "if" branch

Created on 21 Apr 2020  路  3Comments  路  Source: kalessil/phpinspectionsea


| Subject | Details |
| :------------- | :---------------------------------------------------------------------------- |
| Plugin | Php Inspections (EA Extended) |
| Language level | PHP 7.3 |

Current behaviour

It seems that the detection of variable value mutation is not detected properly


image

This snippet throws the warning

<?php

$a = [];
$i = 0;
if (true) {
    $a[$i]['value'] = 'test';
    $i++;
}
$a[$i]['value'] = 'test';

This snippet works as intended

<?php

$a = [];
$i = 0;
$a[$i]['value'] = 'test';
$i++;
$a[$i]['value'] = 'test';

Expected behaviour

No warning, as this is not the same variable being overwritten due to the mutation of the array index value

Environment details


IntelliJ IDEA 2020.1 (Ultimate Edition)
Build #IU-201.6668.121, built on April 8, 2020
Runtime version: 11.0.6+8-b765.25 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Linux 5.3.0-46-generic
GC: ParNew, ConcurrentMarkSweep
Memory: 2416M
Cores: 12
Registry: ide.balloon.shadow.size=0
Non-Bundled Plugins: com.alayouni.ansiHighlight, com.chrisrm.idea.MaterialThemeUI, com.intellij.apacheConfig, com.intellij.ideolog, com.jetbrains.php, com.jetbrains.twig, com.kalessil.phpStorm.phpInspectionsEA, de.espend.idea.php.annotation, de.espend.idea.php.phpunit, net.king2500.plugins.PhpAdvancedAutoComplete, net.seesharpsoft.intellij.plugins.csv, org.jetbrains.plugins.phpstorm-remote-interpreter, org.jetbrains.plugins.vagrant, fr.adrienbrault.idea.symfony2plugin, ru.adelf.idea.dotenv
Current Desktop: ubuntu:GNOME

bug / false-positive fixed

All 3 comments

Thank you for reporting @linaori, I'll look into it.

For myself: traverse and ensure array access expressions uses non-mutable indexes.

Fixed!

Was this page helpful?
0 / 5 - 0 ratings