1--TEST-- 2SimpleXML: casting instances 3--SKIPIF-- 4<?php if (!extension_loaded("simplexml")) print "skip"; ?> 5--FILE-- 6<?php 7 8$xml =<<<EOF 9<people> 10test 11 <person name="Joe"/> 12 <person name="John"> 13 <children> 14 <person name="Joe"/> 15 </children> 16 </person> 17 <person name="Jane"/> 18</people> 19EOF; 20 21$foo = simplexml_load_string( "<foo />" ); 22$people = simplexml_load_string($xml); 23 24var_dump((bool)$foo); 25var_dump((bool)$people); 26var_dump((int)$foo); 27var_dump((int)$people); 28var_dump((double)$foo); 29var_dump((double)$people); 30var_dump((string)$foo); 31var_dump((string)$people); 32var_dump((array)$foo); 33var_dump((array)$people); 34var_dump((object)$foo); 35var_dump((object)$people); 36 37?> 38===DONE=== 39--EXPECTF-- 40bool(false) 41bool(true) 42int(0) 43int(0) 44float(0) 45float(0) 46string(0) "" 47string(15) " 48test 49 50 51 52" 53array(0) { 54} 55array(1) { 56 ["person"]=> 57 array(3) { 58 [0]=> 59 object(SimpleXMLElement)#%d (1) { 60 ["@attributes"]=> 61 array(1) { 62 ["name"]=> 63 string(3) "Joe" 64 } 65 } 66 [1]=> 67 object(SimpleXMLElement)#%d (2) { 68 ["@attributes"]=> 69 array(1) { 70 ["name"]=> 71 string(4) "John" 72 } 73 ["children"]=> 74 object(SimpleXMLElement)#%d (1) { 75 ["person"]=> 76 object(SimpleXMLElement)#%d (1) { 77 ["@attributes"]=> 78 array(1) { 79 ["name"]=> 80 string(3) "Joe" 81 } 82 } 83 } 84 } 85 [2]=> 86 object(SimpleXMLElement)#%d (1) { 87 ["@attributes"]=> 88 array(1) { 89 ["name"]=> 90 string(4) "Jane" 91 } 92 } 93 } 94} 95object(SimpleXMLElement)#%d (0) { 96} 97object(SimpleXMLElement)#%d (1) { 98 ["person"]=> 99 array(3) { 100 [0]=> 101 object(SimpleXMLElement)#%d (1) { 102 ["@attributes"]=> 103 array(1) { 104 ["name"]=> 105 string(3) "Joe" 106 } 107 } 108 [1]=> 109 object(SimpleXMLElement)#%d (2) { 110 ["@attributes"]=> 111 array(1) { 112 ["name"]=> 113 string(4) "John" 114 } 115 ["children"]=> 116 object(SimpleXMLElement)#%d (1) { 117 ["person"]=> 118 object(SimpleXMLElement)#%d (1) { 119 ["@attributes"]=> 120 array(1) { 121 ["name"]=> 122 string(3) "Joe" 123 } 124 } 125 } 126 } 127 [2]=> 128 object(SimpleXMLElement)#%d (1) { 129 ["@attributes"]=> 130 array(1) { 131 ["name"]=> 132 string(4) "Jane" 133 } 134 } 135 } 136} 137===DONE=== 138