Phpinspectionsea: False Positive for Unused -> "Parameter/variable is not used inspection" with objects by reference

Created on 24 Jan 2018  路  6Comments  路  Source: kalessil/phpinspectionsea

"Analyzes functions and methods control flow, reports unused variables and potentially unused variables (such variables are used in write context only)."

A simplified example.

function add(\ArrayObject $Foo, string $string)
{
    // False positive below
    $Foo[] = $string;
}

$Foo   = new ArrayObject();
$Foo[] = 'one';
add($Foo, 'two');
var_dump($Foo);
exit;
bug / false-positive fixed

All 6 comments

@tfettig01, I'm in doubt here. Shouldn't $Foo be returned then as result?

@rentalhost @funivan : your thoughts?

Hello. I think this is definitely false positive.
Maybe this can be fixed in the following manner:

  1. Variable passed as function argument
  2. variable is an object
  3. write operation does not require any read operations

$foo don't need be returned here because it is an object. The method will affect the contents because of $foo[] (once that it is an ArrayObject). So it is a false-positive.

Ok, qualifying as a false-positive.

@tfettig01, I'm in doubt here. Shouldn't $Foo be returned then as result?

False positive? Yes.
Bad code? A definite maybe. Arguments could be made either way.

I'm seeing you took the issue as a false-positive. Thank you.

Fixed

Was this page helpful?
0 / 5 - 0 ratings