xref: /PHP-8.4/ext/simplexml/tests/gh12192.phpt (revision b842ea4f)
1--TEST--
2GH-12192 (SimpleXML infinite loop when getName() is called within foreach)
3--EXTENSIONS--
4simplexml
5--FILE--
6<?php
7
8$xml = "<root><a>1</a><a>2</a></root>";
9$xml = simplexml_load_string($xml);
10
11$a = $xml->a;
12
13foreach ($a as $test) {
14    echo "Iteration\n";
15    var_dump($a->key());
16    var_dump($a->getName());
17    var_dump((string) $test);
18}
19
20var_dump($a);
21
22?>
23--EXPECT--
24Iteration
25string(1) "a"
26string(1) "a"
27string(1) "1"
28Iteration
29string(1) "a"
30string(1) "a"
31string(1) "2"
32object(SimpleXMLElement)#2 (2) {
33  [0]=>
34  string(1) "1"
35  [1]=>
36  string(1) "2"
37}
38