|
| 1 | +--TEST-- |
| 2 | +GH-20553: PHP 8.5.0 regression: PDO::FETCH_CLASSTYPE ignores $constructorArgs |
| 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 | + |
| 15 | +if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.__DIR__ . '/../../pdo/tests/'); |
| 16 | +require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc'; |
| 17 | +$db = PDOTest::factory(); |
| 18 | + |
| 19 | +class dumpy { |
| 20 | + function __construct() { |
| 21 | + echo 'constructor called,' . PHP_EOL . ' my class is ' . |
| 22 | + var_export(get_class($this), true) . PHP_EOL . |
| 23 | + ' input parameters: ' . |
| 24 | + var_export(func_get_args(), true) . PHP_EOL; |
| 25 | + } |
| 26 | + function __set($name, $value) { |
| 27 | + echo var_export($name, true) . ' = ' . var_export($value, true) . |
| 28 | + PHP_EOL; |
| 29 | + } |
| 30 | +} |
| 31 | +class dummy extends dumpy { |
| 32 | +} |
| 33 | + |
| 34 | +$dsn = 'sqlite::memory:'; |
| 35 | +$pdo = method_exists('PDO', 'connect') ? PDO::connect($dsn) : new PDO($dsn); |
| 36 | +$sql = "SELECT 'dummy' pdo_fetch_class_type_class, 'bar' foo, 'dfg' abc;"; |
| 37 | + |
| 38 | +$fetchModes = [ |
| 39 | + 'PDO::FETCH_CLASS' |
| 40 | + => PDO::FETCH_CLASS, |
| 41 | + 'PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE' |
| 42 | + => PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, |
| 43 | + 'PDO::FETCH_CLASS | PDO::FETCH_CLASSTYPE' |
| 44 | + => PDO::FETCH_CLASS | PDO::FETCH_CLASSTYPE, |
| 45 | + 'PDO::FETCH_CLASS | PDO::FETCH_CLASSTYPE | PDO::FETCH_PROPS_LATE' |
| 46 | + => PDO::FETCH_CLASS | PDO::FETCH_CLASSTYPE | PDO::FETCH_PROPS_LATE, |
| 47 | +]; |
| 48 | + |
| 49 | +foreach ($fetchModes as $combinedModes => $fetchMode) { |
| 50 | + echo '## ' . $combinedModes . PHP_EOL; |
| 51 | + $db->query($sql)->fetchAll( |
| 52 | + $fetchMode, |
| 53 | + 'dumpy', |
| 54 | + ['constructor argument #1'] |
| 55 | + ); |
| 56 | + echo PHP_EOL; |
| 57 | +} |
| 58 | +?> |
| 59 | +--EXPECT-- |
| 60 | +## PDO::FETCH_CLASS |
| 61 | +'pdo_fetch_class_type_class' = 'dummy' |
| 62 | +'foo' = 'bar' |
| 63 | +'abc' = 'dfg' |
| 64 | +constructor called, |
| 65 | + my class is 'dumpy' |
| 66 | + input parameters: array ( |
| 67 | + 0 => 'constructor argument #1', |
| 68 | +) |
| 69 | + |
| 70 | +## PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE |
| 71 | +constructor called, |
| 72 | + my class is 'dumpy' |
| 73 | + input parameters: array ( |
| 74 | + 0 => 'constructor argument #1', |
| 75 | +) |
| 76 | +'pdo_fetch_class_type_class' = 'dummy' |
| 77 | +'foo' = 'bar' |
| 78 | +'abc' = 'dfg' |
| 79 | + |
| 80 | +## PDO::FETCH_CLASS | PDO::FETCH_CLASSTYPE |
| 81 | +'foo' = 'bar' |
| 82 | +'abc' = 'dfg' |
| 83 | +constructor called, |
| 84 | + my class is 'dummy' |
| 85 | + input parameters: array ( |
| 86 | + 0 => 'constructor argument #1', |
| 87 | +) |
| 88 | + |
| 89 | +## PDO::FETCH_CLASS | PDO::FETCH_CLASSTYPE | PDO::FETCH_PROPS_LATE |
| 90 | +constructor called, |
| 91 | + my class is 'dummy' |
| 92 | + input parameters: array ( |
| 93 | + 0 => 'constructor argument #1', |
| 94 | +) |
| 95 | +'foo' = 'bar' |
| 96 | +'abc' = 'dfg' |
0 commit comments