Skip to content

Can't make inferences about PDOStatement->fetch? #2529

@duskwuff

Description

@duskwuff

Psalm seems to have trouble dealing with the return value of PDOStatement::fetch(), even with a fetch mode specified.

$p = new \PDO("sqlite:::memory:");
$sth = $p->prepare("SELECT 1");
$sth->execute();
while (($row = $sth->fetch(\PDO::FETCH_ASSOC)) !== false) {
  //    ^-- MixedAssignment: Cannot assign $row to a mixed type
}

The only thing that seems to help is adding a /** @var array|false $row */ directly before $row, inside the condition of the while loop -- but this seems pretty awkward.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions