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