Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions stubs/PDOStatement.stub
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

/**
* @implements Traversable<array<int|string, mixed>>
* @implements IteratorAggregate<array<int|string, mixed>>
* @implements Traversable<mixed>
* @implements IteratorAggregate<mixed>
* @link https://php.net/manual/en/class.pdostatement.php
*/
class PDOStatement implements Traversable, IteratorAggregate
Expand All @@ -21,7 +21,7 @@ class PDOStatement implements Traversable, IteratorAggregate
public function getColumnMeta(int $column) {}

/**
* @return Iterator<mixed, array<int|string, mixed>>
* @return Iterator<mixed, mixed>
*/
public function getIterator() {}
}
2 changes: 1 addition & 1 deletion tests/PHPStan/Analyser/nsrt/bug-8886.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ function testPDOStatementGetIterator(): void {
$pdo = new PDO('sqlite::memory:');
$stmt = $pdo->query('SELECT 1');

assertType('Iterator<mixed, array<int|string, mixed>>', $stmt->getIterator());
assertType('Iterator<mixed, mixed>', $stmt->getIterator());
}
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ public function testBug6348(): void
$this->analyse([__DIR__ . '/data/bug-6348.php'], []);
}

public function testBug14206(): void
{
$this->analyse([__DIR__ . '/data/bug-14206.php'], []);
}

public function testBug9055(): void
{
$this->analyse([__DIR__ . '/data/bug-9055.php'], [
Expand Down
32 changes: 32 additions & 0 deletions tests/PHPStan/Rules/PhpDoc/data/bug-14206.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php declare(strict_types = 1);

namespace Bug14206;

use PDO;
use PDOStatement;

class Test
{
public function test(PDO $db): void
{
/** @var PDOStatement<int,string> */
$statement = $db->prepare('SELECT foo FROM bar');
$statement->setFetchMode(PDO::FETCH_COLUMN, 0);
$statement->execute();
Comment on lines +12 to +15
Copy link
Copy Markdown
Contributor

@staabm staabm Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for better real world use-case coverage, I think it would be good to have another similar example for the PDOStatement<int,array> case - implementation wise I think its good

}

public function test2(PDO $db): void
{
/** @var PDOStatement<int,array<string>> */
$statement = $db->prepare('SELECT foo FROM bar');
$statement->execute();
}

public function test3(PDO $db): void
{
/** @var PDOStatement<int,object> */
$statement = $db->prepare('SELECT foo FROM bar');
$statement->setFetchMode(PDO::FETCH_OBJ, 0);
$statement->execute();
Comment on lines +27 to +30
Copy link
Copy Markdown
Contributor

@staabm staabm Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

@staabm staabm Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe it would make sense to add another test with a object shape

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like it's ok for now

}
}
Loading