Skip to content

Assignment of a reference variable should be consider a use of that variable #126

@alexpott

Description

@alexpott

Consider the following PHP code:

<?php

/**
 * @file
 */

class A {
  protected $prop = [];

  public function __construct() {
    $this->prop[] = 'foo';
  }

  public function &getProp() {
    return $this->prop;
  }

}

function doit() {
  $a = new A();

  $var = &$a->getProp();
  $var = ['bar'];
  return $a;
}

Produces a warning:

----------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
----------------------------------------------------------------------
 23 | WARNING | Unused variable $var.
----------------------------------------------------------------------

But the variable is used to reset the A->prop is being changed and the class is then returned. I think in the case of references we need to consider assignment as the variable being used.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions