1--TEST--
2mysqli_fetch_object() - calling constructor on class wo constructor
3--EXTENSIONS--
4mysqli
5--SKIPIF--
6<?php
7require_once 'skipifconnectfailure.inc';
8?>
9--FILE--
10<?php
11    require 'table.inc';
12    if (!$res = mysqli_query($link, "SELECT id AS ID, label FROM test AS TEST ORDER BY id LIMIT 5")) {
13        printf("[001] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
14    }
15
16    class mysqli_fetch_object_test {
17        public $ID;
18        public $label;
19        public $a = null;
20        public $b = null;
21
22        public function toString() {
23            var_dump($this);
24        }
25    }
26
27    printf("No exception with PHP:\n");
28    var_dump($obj = new mysqli_fetch_object_test(1, 2));
29
30    printf("\nValueError with mysqli. Note that at all other places we throws errors but no exceptions unless the error mode has been changed:\n");
31    try {
32        var_dump($obj = mysqli_fetch_object($res, 'mysqli_fetch_object_test', array(1, 2)));
33    } catch (ValueError $e) {
34        printf("ValueError: %s\n", $e->getMessage());
35    }
36
37    printf("\nFatal error with PHP (but no exception!):\n");
38    var_dump($obj->mysqli_fetch_object_test(1, 2));
39
40    mysqli_close($link);
41    print "done!";
42?>
43--CLEAN--
44<?php
45    require_once 'clean_table.inc';
46?>
47--EXPECTF--
48No exception with PHP:
49object(mysqli_fetch_object_test)#%d (%d) {
50  ["ID"]=>
51  NULL
52  ["label"]=>
53  NULL
54  ["a"]=>
55  NULL
56  ["b"]=>
57  NULL
58}
59
60ValueError with mysqli. Note that at all other places we throws errors but no exceptions unless the error mode has been changed:
61ValueError: mysqli_fetch_object(): Argument #3 ($constructor_args) must be empty when the specified class (mysqli_fetch_object_test) does not have a constructor
62
63Fatal error with PHP (but no exception!):
64
65Fatal error: Uncaught Error: Call to undefined method mysqli_fetch_object_test::mysqli_fetch_object_test() in %s:%d
66Stack trace:
67#0 {main}
68  thrown in %s on line %d
69