diff --git a/stubs/PDOStatement.stub b/stubs/PDOStatement.stub index 46d0be7c5d..f1b32e3d37 100644 --- a/stubs/PDOStatement.stub +++ b/stubs/PDOStatement.stub @@ -19,4 +19,9 @@ class PDOStatement implements Traversable, IteratorAggregate * @return array{name: string, table?: string, native_type?: string, len: int, flags: array, precision: int<0, max>, pdo_type: PDO::PARAM_* }|false */ public function getColumnMeta(int $column) {} + + /** + * @return Iterator + */ + public function getIterator() {} } diff --git a/tests/PHPStan/Analyser/NodeScopeResolverTest.php b/tests/PHPStan/Analyser/NodeScopeResolverTest.php index 516a68397e..6f330a1d9e 100644 --- a/tests/PHPStan/Analyser/NodeScopeResolverTest.php +++ b/tests/PHPStan/Analyser/NodeScopeResolverTest.php @@ -229,6 +229,8 @@ private static function findTestFiles(): iterable yield __DIR__ . '/../Rules/Methods/data/bug-4801.php'; yield __DIR__ . '/../Rules/Arrays/data/narrow-superglobal.php'; yield __DIR__ . '/../Rules/Methods/data/bug-12927.php'; + + // note: files in ./nsrt will be automatically picked up } /** diff --git a/tests/PHPStan/Analyser/nsrt/bug-8886.php b/tests/PHPStan/Analyser/nsrt/bug-8886.php new file mode 100644 index 0000000000..47a385dea5 --- /dev/null +++ b/tests/PHPStan/Analyser/nsrt/bug-8886.php @@ -0,0 +1,13 @@ += 8.0 + +namespace Bug8886; + +use PDO; +use function PHPStan\Testing\assertType; + +function testPDOStatementGetIterator(): void { + $pdo = new PDO('sqlite::memory:'); + $stmt = $pdo->query('SELECT 1'); + + assertType('Iterator', $stmt->getIterator()); +}