Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 11937b3

Browse files
authored
ext/pdo: Add a test for PDO::FETCH_FUNC with a return by-ref callback (#17425)
1 parent bdcb3e9 commit 11937b3

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
--TEST--
2+
PDO Common: PDO::FETCH_FUNC with a simple callback that returns by reference
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+
$table = 'pdo_fetch_function_return_by_ref';
19+
$db->exec("CREATE TABLE {$table} (id int NOT NULL PRIMARY KEY, val1 VARCHAR(10), val2 VARCHAR(10))");
20+
$db->exec("INSERT INTO {$table} VALUES (1, 'A', 'alpha')");
21+
$db->exec("INSERT INTO {$table} VALUES (2, 'B', 'beta')");
22+
$db->exec("INSERT INTO {$table} VALUES (3, 'C', 'gamma')");
23+
$db->exec("INSERT INTO {$table} VALUES (4, 'D', 'delta')");
24+
25+
26+
class Test {
27+
public array $row = [];
28+
29+
public function &addRowAndReturnAll(int $id, string $val, string $val2) {
30+
$this->row = [
31+
$id,
32+
$val,
33+
$val2,
34+
];
35+
return $this->row;
36+
}
37+
}
38+
39+
$test = new Test();
40+
$selectAll = $db->prepare("SELECT * FROM {$table}");
41+
$selectAll->execute();
42+
$result = $selectAll->fetchAll(PDO::FETCH_FUNC, $test->addRowAndReturnAll(...));
43+
var_dump($result);
44+
45+
?>
46+
--CLEAN--
47+
<?php
48+
require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
49+
$db = PDOTest::factory();
50+
PDOTest::dropTableIfExists($db, "pdo_fetch_function_return_by_ref");
51+
?>
52+
--EXPECT--
53+
array(4) {
54+
[0]=>
55+
&array(3) {
56+
[0]=>
57+
int(4)
58+
[1]=>
59+
string(1) "D"
60+
[2]=>
61+
string(5) "delta"
62+
}
63+
[1]=>
64+
&array(3) {
65+
[0]=>
66+
int(4)
67+
[1]=>
68+
string(1) "D"
69+
[2]=>
70+
string(5) "delta"
71+
}
72+
[2]=>
73+
&array(3) {
74+
[0]=>
75+
int(4)
76+
[1]=>
77+
string(1) "D"
78+
[2]=>
79+
string(5) "delta"
80+
}
81+
[3]=>
82+
&array(3) {
83+
[0]=>
84+
int(4)
85+
[1]=>
86+
string(1) "D"
87+
[2]=>
88+
string(5) "delta"
89+
}
90+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /