File: bug80332_1.phpt

package info (click to toggle)
php8.4 8.4.16-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 211,276 kB
  • sloc: ansic: 1,176,142; php: 35,419; sh: 11,964; cpp: 7,208; pascal: 4,951; javascript: 3,091; asm: 2,817; yacc: 2,411; makefile: 696; xml: 446; python: 301; awk: 148
file content (84 lines) | stat: -rw-r--r-- 2,085 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
--TEST--
Bug #80332 (Completely broken array access functionality with DOMNamedNodeMap) - DOMNamedNodeMap variation
--EXTENSIONS--
dom
--FILE--
<?php

$doc = new DOMDocument;

$doc->loadHTML('<span attr1="value1" attr2="value2"></span>');

$x = new DOMXPath($doc);
$span = $x->query('//span')[0];

print "Node name: {$span->nodeName}\n";

function test($span, $key) {
    $key_formatted = match ($key) {
        false => 'false',
        true => 'true',
        null => 'null',
        default => is_string($key) ? "'$key'" : $key,
    };
    echo "Attribute [{$key_formatted}] name: ", $span->attributes[$key]->nodeName ?? '/', "\n";
    echo "Attribute [{$key_formatted}] value: ", $span->attributes[$key]->nodeValue ?? '/', "\n";
    echo "Attribute [{$key_formatted}] isset: ", isset($span->attributes[$key]) ? "yes" : "no", "\n";
    echo "\n";
}

test($span, 0);
test($span, false);
test($span, true);
test($span, null);
test($span, 'attr2');
// This one should fail because there is no 'hi' attribute
test($span, 'hi');
test($span, '0');
test($span, '0.5');
test($span, '1');
// This one should fail because it's out of bounds
test($span, '2147483647');

?>
--EXPECT--
Node name: span
Attribute [0] name: attr1
Attribute [0] value: value1
Attribute [0] isset: yes

Attribute [false] name: attr1
Attribute [false] value: value1
Attribute [false] isset: yes

Attribute [true] name: attr2
Attribute [true] value: value2
Attribute [true] isset: yes

Attribute [null] name: attr1
Attribute [null] value: value1
Attribute [null] isset: yes

Attribute ['attr2'] name: attr2
Attribute ['attr2'] value: value2
Attribute ['attr2'] isset: yes

Attribute ['hi'] name: /
Attribute ['hi'] value: /
Attribute ['hi'] isset: no

Attribute ['0'] name: attr1
Attribute ['0'] value: value1
Attribute ['0'] isset: yes

Attribute ['0.5'] name: attr1
Attribute ['0.5'] value: value1
Attribute ['0.5'] isset: yes

Attribute ['1'] name: attr2
Attribute ['1'] value: value2
Attribute ['1'] isset: yes

Attribute ['2147483647'] name: /
Attribute ['2147483647'] value: /
Attribute ['2147483647'] isset: no