033.phpt 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. --TEST--
  2. SimpleXML: casting instances
  3. --EXTENSIONS--
  4. simplexml
  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. --EXPECTF--
  35. bool(false)
  36. bool(true)
  37. int(0)
  38. int(0)
  39. float(0)
  40. float(0)
  41. string(0) ""
  42. string(15) "
  43. test
  44. "
  45. array(0) {
  46. }
  47. array(1) {
  48. ["person"]=>
  49. array(3) {
  50. [0]=>
  51. object(SimpleXMLElement)#%d (1) {
  52. ["@attributes"]=>
  53. array(1) {
  54. ["name"]=>
  55. string(3) "Joe"
  56. }
  57. }
  58. [1]=>
  59. object(SimpleXMLElement)#%d (2) {
  60. ["@attributes"]=>
  61. array(1) {
  62. ["name"]=>
  63. string(4) "John"
  64. }
  65. ["children"]=>
  66. object(SimpleXMLElement)#%d (1) {
  67. ["person"]=>
  68. object(SimpleXMLElement)#%d (1) {
  69. ["@attributes"]=>
  70. array(1) {
  71. ["name"]=>
  72. string(3) "Joe"
  73. }
  74. }
  75. }
  76. }
  77. [2]=>
  78. object(SimpleXMLElement)#%d (1) {
  79. ["@attributes"]=>
  80. array(1) {
  81. ["name"]=>
  82. string(4) "Jane"
  83. }
  84. }
  85. }
  86. }
  87. object(SimpleXMLElement)#%d (0) {
  88. }
  89. object(SimpleXMLElement)#%d (1) {
  90. ["person"]=>
  91. array(3) {
  92. [0]=>
  93. object(SimpleXMLElement)#%d (1) {
  94. ["@attributes"]=>
  95. array(1) {
  96. ["name"]=>
  97. string(3) "Joe"
  98. }
  99. }
  100. [1]=>
  101. object(SimpleXMLElement)#%d (2) {
  102. ["@attributes"]=>
  103. array(1) {
  104. ["name"]=>
  105. string(4) "John"
  106. }
  107. ["children"]=>
  108. object(SimpleXMLElement)#%d (1) {
  109. ["person"]=>
  110. object(SimpleXMLElement)#%d (1) {
  111. ["@attributes"]=>
  112. array(1) {
  113. ["name"]=>
  114. string(3) "Joe"
  115. }
  116. }
  117. }
  118. }
  119. [2]=>
  120. object(SimpleXMLElement)#%d (1) {
  121. ["@attributes"]=>
  122. array(1) {
  123. ["name"]=>
  124. string(4) "Jane"
  125. }
  126. }
  127. }
  128. }