Skip to content

Add Hack-like option to forget property assignments after function call #929

@muglug

Description

@muglug

This is a feature request for a feature I don't think many are interested in. Still, worth thinking about.

class X {
  /** @var ?int **/
  private $x;

  public function getX(): int {
    $this->x = 5;

    $this->modifyX();

    return $this->x;
  }

  private function modifyX(): void {
    $this->x = null;
  }
}

Hack forbids the above code (though to see it you have to change the property type to one hack understands). Psalm, by default, allows the above code, but a config flag makes it follow Hack's behaviour.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions