xref: /PHP-5.6/ext/dom/tests/bug67949.phpt (revision 37a685ff)
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
51--EXPECTF--
52testing has_dimension
53bool(true)
54bool(false)
55bool(false)
56testing property access
57string(4) "data"
58
59Notice: Trying to get property of non-object in %s on line %d
60NULL
61testing offset not a long
62array(1) {
63  [0]=>
64  string(4) "test"
65}
66
67Notice: Trying to get property of non-object in %s on line %d
68bool(false)
69NULL
70array(1) {
71  [0]=>
72  string(4) "test"
73}
74string(4) "test"
75bool(true)
76string(4) "data"
77string(4) "test"
78string(4) "test"
79bool(true)
80string(4) "data"
81string(4) "test"
82testing read_dimension with null offset
83NULL
84testing attribute access
85string(4) "href"
86==DONE==
87
88