xref: /php-src/ext/pdo_sqlite/tests/bug46139.phpt (revision c1fec9bb)
1--TEST--
2Bug #46139 (PDOStatement->setFetchMode() forgets FETCH_PROPS_LATE)
3--EXTENSIONS--
4pdo_sqlite
5--FILE--
6<?php
7
8require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
9$db = PDOTest::test_factory(__DIR__ . '/common.phpt');
10
11#[AllowDynamicProperties]
12class Person {
13    public $test_prop = NULL;
14    public function __construct() {
15        var_dump($this->test_prop);
16    }
17}
18
19$stmt = $db->query("SELECT 'foo' test_prop, 1");
20$stmt->setFetchMode(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, 'Person');
21$r1 = $stmt->fetch();
22printf("'%s'\n", $r1->test_prop);
23
24$stmt = $db->query("SELECT 'foo' test_prop, 1");
25$stmt->setFetchMode(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, 'Person');
26$r1 = $stmt->fetchAll();
27printf("'%s'\n", $r1[0]->test_prop);
28
29$stmt = $db->query("SELECT 'foo' test_prop, 1");
30$stmt->setFetchMode(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, 'Person');
31$r1 = $stmt->fetch(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE);
32printf("'%s'\n", $r1->test_prop);
33
34?>
35--EXPECT--
36NULL
37'foo'
38NULL
39'foo'
40NULL
41'foo'
42