Skip to content

PDOStatement with bind calls does not resolve types on fetch #770

@xPaw

Description

@xPaw

Test case:

    public function testWithBind(PDO $pdo)
    {
        $stmt = $pdo->prepare('SELECT email, adaid FROM ada WHERE adaid = :adaid');
        $stmt->bindValue('adaid', 1);
        $stmt->execute();
        $all = $stmt->fetch(PDO::FETCH_ASSOC);
        assertType('array{email: string, adaid: int<-32768, 32767>}|false', $all);
    }
-'array{email: string, adaid: int<-32768, 32767>}|false'
+'mixed'

I've roughly boiled it down to PdoMysqlQueryReflector not accepting parameters into simulateQuery which means the query just throws on unbound parameters. Even though this PDOException gets cached, it never gets reported anywhere, so I didn't even know if this was an issue with the PDO calls not being discovered or not.

PdoStatementExecuteMethodRule does try to find and resolve the bind parameters, so I wonder if this should actually attach the type to the statement somehow, so that fetch calls didn't need to simulate the query again.

This also means PdoPrepareDynamicReturnTypeExtension tries to simulate the query with placeholders and gets PDOException due to unbound parameters.

Mildly related to #275.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions