|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace PdoStmtFetchModeTest; |
| 4 | + |
| 5 | +use PDO; |
| 6 | +use function PHPStan\Testing\assertType; |
| 7 | + |
| 8 | +class Foo |
| 9 | +{ |
| 10 | + public function setFetchModeNum(PDO $pdo) |
| 11 | + { |
| 12 | + $bothType = ', array{email: string, 0: string, adaid: int<0, 4294967295>, 1: int<0, 4294967295>}'; |
| 13 | + |
| 14 | + $query = 'SELECT email, adaid FROM ada'; |
| 15 | + $stmt = $pdo->query($query); |
| 16 | + assertType('PDOStatement<array{email: string, 0: string, adaid: int<0, 4294967295>, 1: int<0, 4294967295>}'.$bothType.'>', $stmt); |
| 17 | + |
| 18 | + $stmt->setFetchMode(PDO::FETCH_NUM); |
| 19 | + assertType('PDOStatement<array{string, int<0, 4294967295>}'.$bothType.'>', $stmt); |
| 20 | + |
| 21 | + $result = $stmt->fetch(PDO::FETCH_NUM); |
| 22 | + assertType('array{string, int<0, 4294967295>}|false', $result); |
| 23 | + } |
| 24 | + |
| 25 | + public function setFetchModeAssoc(PDO $pdo) |
| 26 | + { |
| 27 | + $bothType = ', array{email: string, 0: string, adaid: int<0, 4294967295>, 1: int<0, 4294967295>}'; |
| 28 | + |
| 29 | + $query = 'SELECT email, adaid FROM ada'; |
| 30 | + $stmt = $pdo->query($query); |
| 31 | + assertType('PDOStatement<array{email: string, 0: string, adaid: int<0, 4294967295>, 1: int<0, 4294967295>}'.$bothType.'>', $stmt); |
| 32 | + |
| 33 | + $stmt->setFetchMode(PDO::FETCH_ASSOC); |
| 34 | + assertType('PDOStatement<array{email: string, adaid: int<0, 4294967295>}'.$bothType.'>', $stmt); |
| 35 | + |
| 36 | + $result = $stmt->fetch(PDO::FETCH_ASSOC); |
| 37 | + assertType('array{email: string, adaid: int<0, 4294967295>}|false', $result); |
| 38 | + } |
| 39 | + |
| 40 | + public function setFetchModeOnQuery(PDO $pdo) |
| 41 | + { |
| 42 | + $bothType = ', array{email: string, 0: string, adaid: int<0, 4294967295>, 1: int<0, 4294967295>}'; |
| 43 | + |
| 44 | + $query = 'SELECT email, adaid FROM ada'; |
| 45 | + $stmt = $pdo->query($query, PDO::FETCH_NUM); |
| 46 | + assertType('PDOStatement<array{string, int<0, 4294967295>}'.$bothType.'>', $stmt); |
| 47 | + |
| 48 | + $stmt->setFetchMode(PDO::FETCH_ASSOC); |
| 49 | + assertType('PDOStatement<array{email: string, adaid: int<0, 4294967295>}'.$bothType.'>', $stmt); |
| 50 | + |
| 51 | + $result = $stmt->fetch(PDO::FETCH_NUM); |
| 52 | + assertType('array{string, int<0, 4294967295>}|false', $result); |
| 53 | + } |
| 54 | +} |
0 commit comments