xref: /PHP-8.2/ext/dom/tests/bug80332_2.phpt (revision 9f7d8880)
1--TEST--
2Bug #80332 (Completely broken array access functionality with DOMNamedNodeMap) - DOMNodeList variation
3--EXTENSIONS--
4dom
5--FILE--
6<?php
7
8$doc = new DOMDocument;
9$doc->loadXML('<?xml version="1.0"?><span><strong id="1"/><strong id="2"/></span>');
10
11$list = $doc->getElementsByTagName('strong');
12
13function test($list, $key) {
14    $key_formatted = match ($key) {
15        false => 'false',
16        true => 'true',
17        null => 'null',
18        default => is_string($key) ? "'$key'" : $key,
19    };
20    echo "list[$key_formatted] id attribute: ", $list[$key] ? $list[$key]->getAttribute('id') : '/', "\n";
21}
22
23test($list, 0);
24test($list, false);
25test($list, true);
26test($list, null);
27test($list, '0');
28test($list, '0.5');
29test($list, '1');
30// These two should fail because there's no named lookup possible here
31test($list, 'attr2');
32test($list, 'hi');
33// This one should fail because it's out of bounds
34test($list, '2147483647');
35
36?>
37--EXPECT--
38list[0] id attribute: 1
39list[false] id attribute: 1
40list[true] id attribute: 2
41list[null] id attribute: 1
42list['0'] id attribute: 1
43list['0.5'] id attribute: 1
44list['1'] id attribute: 2
45list['attr2'] id attribute: /
46list['hi'] id attribute: /
47list['2147483647'] id attribute: /
48