xref: /PHP-7.2/ext/dom/tests/bug67949.phpt (revision f1d7e3ca)
1--TEST--
2Bug #67949: DOMNodeList elements should be accessible through array notation
3--FILE--
4<?php
5
6$html = <<<HTML
7<div>data</div>
8<a href="test">hello world</a>
9HTML;
10$doc = new DOMDocument;
11$doc->loadHTML($html);
12
13$nodes = $doc->getElementsByTagName('div');
14
15echo "testing has_dimension\n";
16var_dump(isset($nodes[0]));
17var_dump(isset($nodes[1]));
18var_dump(isset($nodes[-1]));
19
20echo "testing property access\n";
21var_dump($nodes[0]->textContent);
22var_dump($nodes[1]->textContent);
23
24echo "testing offset not a long\n";
25$offset = ['test'];
26var_dump($offset);
27var_dump(isset($nodes[$offset]), $nodes[$offset]->textContent);
28var_dump($offset);
29
30$something = 'test';
31$offset = &$something;
32
33var_dump($offset);
34var_dump(isset($nodes[$offset]), $nodes[$offset]->textContent);
35var_dump($offset);
36
37$offset = 'test';
38var_dump($offset);
39var_dump(isset($nodes[$offset]), $nodes[$offset]->textContent);
40var_dump($offset);
41
42echo "testing read_dimension with null offset\n";
43var_dump($nodes[][] = 1);
44
45echo "testing attribute access\n";
46$anchor = $doc->getElementsByTagName('a')[0];
47var_dump($anchor->attributes[0]->name);
48
49echo "==DONE==\n";
50--EXPECTF--
51testing has_dimension
52bool(true)
53bool(false)
54bool(false)
55testing property access
56string(4) "data"
57
58Notice: Trying to get property 'textContent' of non-object in %s on line %d
59NULL
60testing offset not a long
61array(1) {
62  [0]=>
63  string(4) "test"
64}
65
66Notice: Trying to get property 'textContent' of non-object in %s on line %d
67bool(false)
68NULL
69array(1) {
70  [0]=>
71  string(4) "test"
72}
73string(4) "test"
74bool(true)
75string(4) "data"
76string(4) "test"
77string(4) "test"
78bool(true)
79string(4) "data"
80string(4) "test"
81testing read_dimension with null offset
82NULL
83testing attribute access
84string(4) "href"
85==DONE==
86