xref: /PHP-8.0/ext/pgsql/tests/80_bug24499.phpt (revision f8d79582)
1--TEST--
2Bug #24499 (Notice: Undefined property: stdClass::)
3--SKIPIF--
4<?php
5require_once('skipif.inc');
6?>
7--FILE--
8<?php
9
10require_once('config.inc');
11
12$dbh = @pg_connect($conn_str);
13if (!$dbh) {
14    die ("Could not connect to the server");
15}
16
17@pg_query("DROP SEQUENCE id_id_seq");
18@pg_query("DROP TABLE id");
19pg_query("CREATE TABLE id (id SERIAL, t INT)");
20
21for ($i=0; $i<4; $i++) {
22    pg_query("INSERT INTO id (t) VALUES ($i)");
23}
24
25class Id
26{
27    public $id;
28
29    public function getId()
30    {
31        global $dbh;
32
33        $q  = pg_query($dbh, "SELECT id FROM id");
34        print_r(pg_fetch_array($q));
35        print_r(pg_fetch_array($q));
36        $id = pg_fetch_object($q);
37        var_dump($id);
38        return $id->id;
39    }
40}
41
42$id = new Id();
43var_dump($id->getId());
44
45pg_close($dbh);
46
47echo "Done\n";
48
49?>
50--EXPECTF--
51Array
52(
53    [0] => 1
54    [id] => 1
55)
56Array
57(
58    [0] => 2
59    [id] => 2
60)
61object(stdClass)#%d (1) {
62  ["id"]=>
63  string(1) "3"
64}
65string(1) "3"
66Done
67