xref: /PHP-8.2/ext/pdo_sqlite/tests/bug46139.phpt (revision 902d6439)
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 = NULL;
14    public function __construct() {
15        var_dump($this->test);
16    }
17}
18
19$stmt = $db->query("SELECT 'foo' test, 1");
20$stmt->setFetchMode(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, 'Person');
21$r1 = $stmt->fetch();
22printf("'%s'\n", $r1->test);
23
24$stmt = $db->query("SELECT 'foo' test, 1");
25$stmt->setFetchMode(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, 'Person');
26$r1 = $stmt->fetchAll();
27printf("'%s'\n", $r1[0]->test);
28
29$stmt = $db->query("SELECT 'foo' test, 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);
33
34?>
35--EXPECT--
36NULL
37'foo'
38NULL
39'foo'
40NULL
41'foo'
42