1--TEST-- 2PDO Common: Bug #44173 (PDO->query() parameter parsing/checking needs an update) 3--SKIPIF-- 4<?php 5if (!extension_loaded('pdo')) die('skip'); 6$dir = getenv('REDIR_TEST_DIR'); 7if (false == $dir) die('skip no driver'); 8require_once $dir . 'pdo_test.inc'; 9PDOTest::skip(); 10?> 11--FILE-- 12<?php 13if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.__DIR__ . '/../../pdo/tests/'); 14require getenv('REDIR_TEST_DIR') . 'pdo_test.inc'; 15$db = PDOTest::factory(); 16 17$db->exec("CREATE TABLE test (x int)"); 18$db->exec("INSERT INTO test VALUES (1)"); 19 20 21// Bug entry [2] -- 1 is PDO::FETCH_LAZY 22try { 23 $stmt = $db->query("SELECT * FROM test", PDO::FETCH_LAZY, 0, []); 24 var_dump($stmt); 25} catch (\TypeError $e) { 26 echo $e->getMessage(), \PHP_EOL; 27} 28 29 30// Bug entry [3] 31try { 32 $stmt = $db->query("SELECT * FROM test", 'abc'); 33} catch (TypeError $e) { 34 echo $e->getMessage(), "\n"; 35} 36 37// Bug entry [4] 38try { 39 $stmt = $db->query("SELECT * FROM test", PDO::FETCH_CLASS, 0, 0, 0); 40 var_dump($stmt); 41} catch (\ArgumentCountError $e) { 42 echo $e->getMessage(), \PHP_EOL; 43} 44 45 46// Bug entry [5] 47try { 48 $stmt = $db->query("SELECT * FROM test", PDO::FETCH_INTO); 49 var_dump($stmt); 50} catch (\ArgumentCountError $e) { 51 echo $e->getMessage(), \PHP_EOL; 52} 53 54 55// Bug entry [6] 56try { 57 $stmt = $db->query("SELECT * FROM test", PDO::FETCH_COLUMN); 58 var_dump($stmt); 59} catch (\ArgumentCountError $e) { 60 echo $e->getMessage(), \PHP_EOL; 61} 62 63 64// Bug entry [7] 65try { 66 $stmt = $db->query("SELECT * FROM test", PDO::FETCH_CLASS); 67 var_dump($stmt); 68} catch (\ArgumentCountError $e) { 69 echo $e->getMessage(), \PHP_EOL; 70} 71 72 73?> 74--EXPECT-- 75PDO::query() expects exactly 2 arguments for the fetch mode provided, 4 given 76PDO::query(): Argument #2 ($fetchMode) must be of type ?int, string given 77PDO::query() expects at most 4 arguments for the fetch mode provided, 5 given 78PDO::query() expects exactly 3 arguments for the fetch mode provided, 2 given 79PDO::query() expects exactly 3 arguments for the fetch mode provided, 2 given 80PDO::query() expects at least 3 arguments for the fetch mode provided, 2 given 81