From 00cd8e5b1f27880dc85797dd90274638fcddf00c Mon Sep 17 00:00:00 2001 From: Ilia Urvachev Date: Tue, 29 Sep 2026 19:31:17 +0200 Subject: [PATCH] fix: silence PDOStatement::setFetchMode signature notice on PHP 8 PHP's stubs declare `PDOStatement::setFetchMode(): true`, so the `bool` override was reported as an incompatible signature. Keep `bool` to stay compatible with PHP 8.0/8.1 (the `true` return type needs PHP 8.2) and mark the method with `#[\ReturnTypeWillChange]`, as the other overrides in this class already do. `universalSetFetchMode()` only ever returns `true`, which the phpdoc of both methods now states. Adds a regression test for `setFetchMode()`, which had no coverage. --- src/FakePdoStatementTrait.php | 1 + src/Php8/FakePdoStatement.php | 2 ++ tests/FakePdoTest.php | 15 +++++++++++++++ 3 files changed, 18 insertions(+) diff --git a/src/FakePdoStatementTrait.php b/src/FakePdoStatementTrait.php index ce33ca36..50980cb9 100644 --- a/src/FakePdoStatementTrait.php +++ b/src/FakePdoStatementTrait.php @@ -514,6 +514,7 @@ function ($row) use ($fetch_argument, $ctor_args) { /** * @param int $fetch_style * @param mixed $args + * @return true */ public function universalSetFetchMode(int $mode, ...$args) : bool { diff --git a/src/Php8/FakePdoStatement.php b/src/Php8/FakePdoStatement.php index 8156ba08..f4d1646f 100644 --- a/src/Php8/FakePdoStatement.php +++ b/src/Php8/FakePdoStatement.php @@ -28,7 +28,9 @@ public function fetchAll(int $fetch_style = -123, ...$args) : array /** * @param int $fetch_style * @param mixed $args + * @return true */ + #[\ReturnTypeWillChange] public function setFetchMode(int $mode, ...$args) : bool { return $this->universalSetFetchMode($mode, ...$args); diff --git a/tests/FakePdoTest.php b/tests/FakePdoTest.php index fc31d782..1e7bd0a1 100644 --- a/tests/FakePdoTest.php +++ b/tests/FakePdoTest.php @@ -28,6 +28,21 @@ public function testMinimalTransaction(): void self::assertFalse($pdo->inTransaction()); } + public function testSetFetchMode(): void + { + $pdo = self::getPdo('mysql:foo;dbname=test;'); + $pdo->prepare('CREATE TABLE `foo` (`id` INT NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci')->execute(); + $pdo->prepare('INSERT INTO `foo` (`id`) VALUES (1)')->execute(); + + $statement = $pdo->prepare('SELECT `id` FROM `foo`'); + + self::assertTrue($statement->setFetchMode(\PDO::FETCH_ASSOC)); + + $statement->execute(); + + self::assertSame([['id' => '1']], $statement->fetchAll()); + } + /** * @dataProvider quotationStringProvider */