Analysis fails on PHP project with NullPointerException, fails on foreach($arrayOfArrays as list($item1, $item2)) {}

113 views Asked by At

Example code:

foreach ([["1", "2"], ["one", "two"]] as list($one, $two)) {
    print $one." => ".$two.PHP_EOL;
}

//expected:
// 1 => 2
// one => two

Removing similar from my source file allowed the analysis to complete where it didn't before:

foreach ($criteria->getObjects() as list($objectTypeId, $objectId)) {
    //...
}

This is perfectly valid PHP and runs just fine.

1

There are 1 answers

0
Linda - SonarSource Team On

So here is the related ticket SONARPHP-472. It will be fixed in next version 2.7 of the PHP Plugin. The only workarounds in the mean time are:

  • deactivate the rule
  • exclude file from the analysis