xref: /PHP-5.4/ext/simplexml/tests/bug38347.phpt (revision 7c750656)
1--TEST--
2Bug #38347 (Segmentation fault when using foreach with an unknown/empty SimpleXMLElement)
3--SKIPIF--
4<?php if (!extension_loaded("simplexml")) print "skip"; ?>
5--FILE--
6<?php
7
8function iterate($xml)
9{
10    print_r($xml);
11    foreach ($xml->item as $item) {
12        echo "This code will crash!";
13    }
14}
15
16$xmlstr = "<xml><item>Item 1</item><item>Item 2</item></xml>";
17$xml = simplexml_load_string($xmlstr);
18iterate($xml->unknown);
19
20echo "Done\n";
21?>
22--EXPECTF--
23SimpleXMLElement Object
24(
25)
26
27Warning: Invalid argument supplied for foreach() in %sbug38347.php on line 6
28Done
29