xref: /php-src/ext/pdo/tests/pdo_035.phpt (revision b4e272c5)
1--TEST--
2PDO Common: PDORow + get_parent_class()
3--EXTENSIONS--
4pdo
5--SKIPIF--
6<?php
7$dir = getenv('REDIR_TEST_DIR');
8if (false == $dir) die('skip no driver');
9require_once $dir . 'pdo_test.inc';
10PDOTest::skip();
11?>
12--FILE--
13<?php
14if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.__DIR__ . '/../../pdo/tests/');
15require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
16$db = PDOTest::factory();
17
18const TABLE_NAME = 'test_pdo_35_pdo_row';
19$db->exec('CREATE TABLE ' . TABLE_NAME .' (id int, name varchar(10))');
20$db->exec('INSERT INTO ' . TABLE_NAME .' VALUES (23, \'0\')');
21
22$stmt = $db->prepare('SELECT id, name FROM ' . TABLE_NAME);
23$stmt->execute();
24$result = $stmt->fetch(PDO::FETCH_LAZY);
25
26var_dump($result);
27var_dump(get_parent_class($result));
28
29foreach ([0, "0", "id", "name", 1] as $offset) {
30    echo 'Offset: ', var_export($offset), PHP_EOL;
31    $offsetRef = &$offset;
32
33    echo 'Dimension:', PHP_EOL;
34    echo 'Isset:', PHP_EOL;
35    var_dump(isset($result[$offset]));
36    var_dump(isset($result[$offsetRef]));
37    echo 'Empty:', PHP_EOL;
38    var_dump(empty($result[$offset]));
39    var_dump(empty($result[$offsetRef]));
40    echo 'Null coalesce:', PHP_EOL;
41    var_dump($result[$offset] ?? "default");
42    var_dump($result[$offsetRef] ?? "default");
43    echo 'Read:', PHP_EOL;
44    var_dump($result[$offset]);
45    var_dump($result[$offsetRef]);
46    echo 'Property:', PHP_EOL;
47    echo 'Isset:', PHP_EOL;
48    var_dump(isset($result->{$offset}));
49    var_dump(isset($result->{$offsetRef}));
50    echo 'Empty:', PHP_EOL;
51    var_dump(empty($result->{$offset}));
52    var_dump(empty($result->{$offsetRef}));
53    echo 'Null coalesce:', PHP_EOL;
54    var_dump($result->{$offset} ?? "default");
55    var_dump($result->{$offsetRef} ?? "default");
56    echo 'Read:', PHP_EOL;
57    var_dump($result->{$offset});
58    var_dump($result->{$offsetRef});
59}
60
61echo 'Errors:', PHP_EOL;
62try {
63    $result[0] = 1;
64} catch (Error $e) {
65    echo $e->getMessage(), "\n";
66}
67try {
68    $result[] = 1;
69} catch (Error $e) {
70    echo $e->getMessage(), "\n";
71}
72try {
73    $refResult = &$result[0];
74} catch (Error $e) {
75    echo $e->getMessage(), "\n";
76}
77try {
78    $refResult = &$result[];
79} catch (Error $e) {
80    echo $e->getMessage(), "\n";
81}
82try {
83    unset($result[0]);
84} catch (Error $e) {
85    echo $e->getMessage(), "\n";
86}
87try {
88    $result->foo = 1;
89} catch (Error $e) {
90    echo $e->getMessage(), "\n";
91}
92try {
93    unset($result->foo);
94} catch (Error $e) {
95    echo $e->getMessage(), "\n";
96}
97
98?>
99--CLEAN--
100<?php
101if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.__DIR__ . '/../../pdo/tests/');
102require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
103$db = PDOTest::factory();
104$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);
105
106const TABLE_NAME = 'test_pdo_35_pdo_row';
107$db->exec("DROP TABLE " . TABLE_NAME);
108?>
109--EXPECTF--
110object(PDORow)#3 (3) {
111  ["queryString"]=>
112  string(40) "SELECT id, name FROM test_pdo_35_pdo_row"
113  ["id"]=>
114  string(2) "23"
115  ["name"]=>
116  string(1) "0"
117}
118bool(false)
119Offset: 0
120Dimension:
121Isset:
122bool(true)
123bool(true)
124Empty:
125bool(false)
126bool(false)
127Null coalesce:
128string(2) "23"
129string(2) "23"
130Read:
131string(2) "23"
132string(2) "23"
133Property:
134Isset:
135bool(true)
136bool(true)
137Empty:
138bool(false)
139bool(false)
140Null coalesce:
141string(2) "23"
142string(2) "23"
143Read:
144string(2) "23"
145string(2) "23"
146Offset: '0'
147Dimension:
148Isset:
149bool(true)
150bool(true)
151Empty:
152bool(false)
153bool(false)
154Null coalesce:
155string(2) "23"
156string(2) "23"
157Read:
158string(2) "23"
159string(2) "23"
160Property:
161Isset:
162bool(true)
163bool(true)
164Empty:
165bool(false)
166bool(false)
167Null coalesce:
168string(2) "23"
169string(2) "23"
170Read:
171string(2) "23"
172string(2) "23"
173Offset: 'id'
174Dimension:
175Isset:
176bool(true)
177bool(true)
178Empty:
179bool(false)
180bool(false)
181Null coalesce:
182string(2) "23"
183string(2) "23"
184Read:
185string(2) "23"
186string(2) "23"
187Property:
188Isset:
189bool(true)
190bool(true)
191Empty:
192bool(false)
193bool(false)
194Null coalesce:
195string(2) "23"
196string(2) "23"
197Read:
198string(2) "23"
199string(2) "23"
200Offset: 'name'
201Dimension:
202Isset:
203bool(true)
204bool(true)
205Empty:
206bool(true)
207bool(true)
208Null coalesce:
209string(1) "0"
210string(1) "0"
211Read:
212string(1) "0"
213string(1) "0"
214Property:
215Isset:
216bool(true)
217bool(true)
218Empty:
219bool(true)
220bool(true)
221Null coalesce:
222string(1) "0"
223string(1) "0"
224Read:
225string(1) "0"
226string(1) "0"
227Offset: 1
228Dimension:
229Isset:
230bool(true)
231bool(true)
232Empty:
233bool(true)
234bool(true)
235Null coalesce:
236string(1) "0"
237string(1) "0"
238Read:
239string(1) "0"
240string(1) "0"
241Property:
242Isset:
243bool(true)
244bool(true)
245Empty:
246bool(true)
247bool(true)
248Null coalesce:
249string(1) "0"
250string(1) "0"
251Read:
252string(1) "0"
253string(1) "0"
254Errors:
255Cannot write to PDORow offset
256Cannot append to PDORow offset
257
258Notice: Indirect modification of overloaded element of PDORow has no effect in %s on line %d
259Cannot append to PDORow offset
260Cannot unset PDORow offset
261Cannot write to PDORow property
262Cannot unset PDORow property
263