|
| 1 | +--TEST-- |
| 2 | +PDO Common: PDO::FETCH_CLASS using mixed string and int arguments in constructor array |
| 3 | +--EXTENSIONS-- |
| 4 | +pdo |
| 5 | +--SKIPIF-- |
| 6 | +<?php |
| 7 | +$dir = getenv('REDIR_TEST_DIR'); |
| 8 | +if (false == $dir) die('skip no driver'); |
| 9 | +require_once $dir . 'pdo_test.inc'; |
| 10 | +PDOTest::skip(); |
| 11 | +?> |
| 12 | +--FILE-- |
| 13 | +<?php |
| 14 | +if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.__DIR__ . '/../../pdo/tests/'); |
| 15 | +require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc'; |
| 16 | +$db = PDOTest::factory(); |
| 17 | + |
| 18 | +$db->exec('CREATE TABLE pdo_fetch_class_ctor_with_named_arguments_positional_after_named(id int NOT NULL PRIMARY KEY, val VARCHAR(10), val2 VARCHAR(10))'); |
| 19 | +$db->exec("INSERT INTO pdo_fetch_class_ctor_with_named_arguments_positional_after_named VALUES(1, 'A', 'AA')"); |
| 20 | +$db->exec("INSERT INTO pdo_fetch_class_ctor_with_named_arguments_positional_after_named VALUES(2, 'B', 'BB')"); |
| 21 | +$db->exec("INSERT INTO pdo_fetch_class_ctor_with_named_arguments_positional_after_named VALUES(3, 'C', 'CC')"); |
| 22 | + |
| 23 | +$stmt = $db->prepare('SELECT id, val, val2 from pdo_fetch_class_ctor_with_named_arguments_positional_after_named'); |
| 24 | + |
| 25 | +class TestBase |
| 26 | +{ |
| 27 | + public $id; |
| 28 | + protected $val; |
| 29 | + private $val2; |
| 30 | + |
| 31 | + public function __construct(string $a, string $b) { |
| 32 | + echo 'Value of $a: ', $a, PHP_EOL, |
| 33 | + 'Value of $b: ', $b, PHP_EOL; |
| 34 | + } |
| 35 | +} |
| 36 | +$stmt->execute(); |
| 37 | + |
| 38 | +try { |
| 39 | + var_dump($stmt->fetchAll(PDO::FETCH_CLASS, 'TestBase', ['b' => 'My key is B', 'No key'])); |
| 40 | +} catch (\Throwable $e) { |
| 41 | + echo $e::class, ': ', $e->getMessage(), \PHP_EOL; |
| 42 | +} |
| 43 | + |
| 44 | +?> |
| 45 | +--CLEAN-- |
| 46 | +<?php |
| 47 | +require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc'; |
| 48 | +$db = PDOTest::factory(); |
| 49 | +PDOTest::dropTableIfExists($db, "pdo_fetch_class_ctor_with_named_arguments_positional_after_named"); |
| 50 | +?> |
| 51 | +--EXPECTF-- |
| 52 | +Value of $a: My key is B |
| 53 | +Value of $b: No key |
| 54 | +Value of $a: My key is B |
| 55 | +Value of $b: No key |
| 56 | +Value of $a: My key is B |
| 57 | +Value of $b: No key |
| 58 | +array(3) { |
| 59 | + [0]=> |
| 60 | + object(TestBase)#%d (3) { |
| 61 | + ["id"]=> |
| 62 | + string(1) "1" |
| 63 | + ["val":protected]=> |
| 64 | + string(1) "A" |
| 65 | + ["val2":"TestBase":private]=> |
| 66 | + string(2) "AA" |
| 67 | + } |
| 68 | + [1]=> |
| 69 | + object(TestBase)#%d (3) { |
| 70 | + ["id"]=> |
| 71 | + string(1) "2" |
| 72 | + ["val":protected]=> |
| 73 | + string(1) "B" |
| 74 | + ["val2":"TestBase":private]=> |
| 75 | + string(2) "BB" |
| 76 | + } |
| 77 | + [2]=> |
| 78 | + object(TestBase)#%d (3) { |
| 79 | + ["id"]=> |
| 80 | + string(1) "3" |
| 81 | + ["val":protected]=> |
| 82 | + string(1) "C" |
| 83 | + ["val2":"TestBase":private]=> |
| 84 | + string(2) "CC" |
| 85 | + } |
| 86 | +} |
0 commit comments