From 0ab1006833752d1ec70dacd6da37f16111917f52 Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Thu, 9 Jan 2025 22:14:52 +0000 Subject: [PATCH] ext/pdo: Add a test for PDO::FETCH_FUNC with a return by-ref callback --- .../pdo_fetch_function_return_by_ref.phpt | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 ext/pdo/tests/pdo_fetch_function_return_by_ref.phpt diff --git a/ext/pdo/tests/pdo_fetch_function_return_by_ref.phpt b/ext/pdo/tests/pdo_fetch_function_return_by_ref.phpt new file mode 100644 index 0000000000000..68157e2623d3f --- /dev/null +++ b/ext/pdo/tests/pdo_fetch_function_return_by_ref.phpt @@ -0,0 +1,90 @@ +--TEST-- +PDO Common: PDO::FETCH_FUNC with a simple callback that returns by reference +--EXTENSIONS-- +pdo +--SKIPIF-- + +--FILE-- +exec("CREATE TABLE {$table} (id int NOT NULL PRIMARY KEY, val1 VARCHAR(10), val2 VARCHAR(10))"); +$db->exec("INSERT INTO {$table} VALUES (1, 'A', 'alpha')"); +$db->exec("INSERT INTO {$table} VALUES (2, 'B', 'beta')"); +$db->exec("INSERT INTO {$table} VALUES (3, 'C', 'gamma')"); +$db->exec("INSERT INTO {$table} VALUES (4, 'D', 'delta')"); + + +class Test { + public array $row = []; + + public function &addRowAndReturnAll(int $id, string $val, string $val2) { + $this->row = [ + $id, + $val, + $val2, + ]; + return $this->row; + } +} + +$test = new Test(); +$selectAll = $db->prepare("SELECT * FROM {$table}"); +$selectAll->execute(); +$result = $selectAll->fetchAll(PDO::FETCH_FUNC, $test->addRowAndReturnAll(...)); +var_dump($result); + +?> +--CLEAN-- + +--EXPECT-- +array(4) { + [0]=> + &array(3) { + [0]=> + int(4) + [1]=> + string(1) "D" + [2]=> + string(5) "delta" + } + [1]=> + &array(3) { + [0]=> + int(4) + [1]=> + string(1) "D" + [2]=> + string(5) "delta" + } + [2]=> + &array(3) { + [0]=> + int(4) + [1]=> + string(1) "D" + [2]=> + string(5) "delta" + } + [3]=> + &array(3) { + [0]=> + int(4) + [1]=> + string(1) "D" + [2]=> + string(5) "delta" + } +}