033.phpt 2.3 KB

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