|
| 1 | +--TEST-- |
| 2 | +Bug #80332 (Completely broken array access functionality with DOMNamedNodeMap) - DOMNamedNodeMap variation |
| 3 | +--EXTENSIONS-- |
| 4 | +dom |
| 5 | +--FILE-- |
| 6 | +<?php |
| 7 | + |
| 8 | +$doc = new DOMDocument; |
| 9 | + |
| 10 | +$doc->loadHTML('<span attr1="value1" attr2="value2"></span>'); |
| 11 | + |
| 12 | +$x = new DOMXPath($doc); |
| 13 | +$span = $x->query('//span')[0]; |
| 14 | + |
| 15 | +print "Node name: {$span->nodeName}\n"; |
| 16 | + |
| 17 | +function test($span, $key) { |
| 18 | + $key_formatted = match ($key) { |
| 19 | + false => 'false', |
| 20 | + true => 'true', |
| 21 | + null => 'null', |
| 22 | + default => is_string($key) ? "'$key'" : $key, |
| 23 | + }; |
| 24 | + echo "Attribute [{$key_formatted}] name: ", $span->attributes[$key]->nodeName ?? '/', "\n"; |
| 25 | + echo "Attribute [{$key_formatted}] value: ", $span->attributes[$key]->nodeValue ?? '/', "\n"; |
| 26 | + echo "Attribute [{$key_formatted}] isset: ", isset($span->attributes[$key]) ? "yes" : "no", "\n"; |
| 27 | + echo "\n"; |
| 28 | +} |
| 29 | + |
| 30 | +test($span, 0); |
| 31 | +test($span, false); |
| 32 | +test($span, true); |
| 33 | +test($span, null); |
| 34 | +test($span, 'attr2'); |
| 35 | +// This one should fail because there is no 'hi' attribute |
| 36 | +test($span, 'hi'); |
| 37 | +test($span, '0'); |
| 38 | +test($span, '0.5'); |
| 39 | +test($span, '1'); |
| 40 | +// This one should fail because it's out of bounds |
| 41 | +test($span, '2147483647'); |
| 42 | + |
| 43 | +?> |
| 44 | +--EXPECT-- |
| 45 | +Node name: span |
| 46 | +Attribute [0] name: attr1 |
| 47 | +Attribute [0] value: value1 |
| 48 | +Attribute [0] isset: yes |
| 49 | + |
| 50 | +Attribute [false] name: attr1 |
| 51 | +Attribute [false] value: value1 |
| 52 | +Attribute [false] isset: yes |
| 53 | + |
| 54 | +Attribute [true] name: attr2 |
| 55 | +Attribute [true] value: value2 |
| 56 | +Attribute [true] isset: yes |
| 57 | + |
| 58 | +Attribute [null] name: attr1 |
| 59 | +Attribute [null] value: value1 |
| 60 | +Attribute [null] isset: yes |
| 61 | + |
| 62 | +Attribute ['attr2'] name: attr1 |
| 63 | +Attribute ['attr2'] value: value1 |
| 64 | +Attribute ['attr2'] isset: yes |
| 65 | + |
| 66 | +Attribute ['hi'] name: attr1 |
| 67 | +Attribute ['hi'] value: value1 |
| 68 | +Attribute ['hi'] isset: yes |
| 69 | + |
| 70 | +Attribute ['0'] name: attr1 |
| 71 | +Attribute ['0'] value: value1 |
| 72 | +Attribute ['0'] isset: yes |
| 73 | + |
| 74 | +Attribute ['0.5'] name: attr1 |
| 75 | +Attribute ['0.5'] value: value1 |
| 76 | +Attribute ['0.5'] isset: yes |
| 77 | + |
| 78 | +Attribute ['1'] name: attr2 |
| 79 | +Attribute ['1'] value: value2 |
| 80 | +Attribute ['1'] isset: yes |
| 81 | + |
| 82 | +Attribute ['2147483647'] name: / |
| 83 | +Attribute ['2147483647'] value: / |
| 84 | +Attribute ['2147483647'] isset: no |
0 commit comments