1--TEST--
2XMLReader::fromStream() - custom constructor
3--EXTENSIONS--
4xmlreader
5--FILE--
6<?php
7class CustomXMLReader extends XMLReader {
8    public int $myField;
9
10    public function __construct() {
11        $this->myField = 1234;
12        echo "hello world\n";
13    }
14}
15
16$h = fopen("php://memory", "w+");
17fwrite($h, "<root/>");
18fseek($h, 0);
19
20$reader = CustomXMLReader::fromStream($h, encoding: "UTF-8");
21try {
22    var_dump($reader);
23} catch (Error $e) {
24    echo $e->getMessage(), "\n";
25}
26var_dump($reader->read());
27var_dump($reader->nodeType);
28
29fclose($h);
30?>
31--EXPECTF--
32hello world
33object(CustomXMLReader)#%d (14) {
34  ["myField"]=>
35  int(1234)
36  ["attributeCount"]=>
37  int(0)
38  ["baseURI"]=>
39  string(0) ""
40  ["depth"]=>
41  int(0)
42  ["hasAttributes"]=>
43  bool(false)
44  ["hasValue"]=>
45  bool(false)
46  ["isDefault"]=>
47  bool(false)
48  ["localName"]=>
49  string(0) ""
50  ["name"]=>
51  string(0) ""
52  ["namespaceURI"]=>
53  string(0) ""
54  ["nodeType"]=>
55  int(0)
56  ["prefix"]=>
57  string(0) ""
58  ["value"]=>
59  string(0) ""
60  ["xmlLang"]=>
61  string(0) ""
62}
63Failed to read property because no XML data has been read yet
64bool(true)
65int(1)
66