xml_parse_variation1.phpt 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. --TEST--
  2. Test xml_parse() function : usage variations - different types of parser
  3. --SKIPIF--
  4. <?php
  5. if (!extension_loaded("xml")) {
  6. print "skip - XML extension not loaded";
  7. }
  8. ?>
  9. --FILE--
  10. <?php
  11. /* Prototype : proto int xml_parse(resource parser, string data [, int isFinal])
  12. * Description: Start parsing an XML document
  13. * Source code: ext/xml/xml.c
  14. * Alias to functions:
  15. */
  16. echo "*** Testing xml_parse() : usage variations ***\n";
  17. error_reporting(E_ALL & ~E_NOTICE);
  18. class aClass {
  19. function __toString() {
  20. return "Some Ascii Data";
  21. }
  22. }
  23. // Initialise function arguments not being substituted (if any)
  24. $data = 'string_val';
  25. $isFinal = 10;
  26. //get an unset variable
  27. $unset_var = 10;
  28. unset ($unset_var);
  29. $fp = fopen(__FILE__, "r");
  30. //array of values to iterate over
  31. $values = array(
  32. // int data
  33. 0,
  34. 1,
  35. 12345,
  36. -2345,
  37. // float data
  38. 10.5,
  39. -10.5,
  40. 10.1234567e10,
  41. 10.7654321E-10,
  42. .5,
  43. // array data
  44. array(),
  45. array(0),
  46. array(1),
  47. array(1, 2),
  48. array('color' => 'red', 'item' => 'pen'),
  49. // null data
  50. NULL,
  51. null,
  52. // boolean data
  53. true,
  54. false,
  55. TRUE,
  56. FALSE,
  57. // empty data
  58. "",
  59. '',
  60. // string data
  61. "string",
  62. 'string',
  63. // object data
  64. new aClass(),
  65. // resource data
  66. $fp,
  67. // undefined data
  68. $undefined_var,
  69. // unset data
  70. $unset_var,
  71. );
  72. // loop through each element of the array for parser
  73. foreach($values as $value) {
  74. echo @"\nArg value $value \n";
  75. var_dump( xml_parse($value, $data, $isFinal) );
  76. };
  77. fclose($fp);
  78. echo "Done";
  79. ?>
  80. --EXPECTF--
  81. *** Testing xml_parse() : usage variations ***
  82. Arg value 0
  83. Warning: xml_parse() expects parameter 1 to be resource, int given in %s on line %d
  84. NULL
  85. Arg value 1
  86. Warning: xml_parse() expects parameter 1 to be resource, int given in %s on line %d
  87. NULL
  88. Arg value 12345
  89. Warning: xml_parse() expects parameter 1 to be resource, int given in %s on line %d
  90. NULL
  91. Arg value -2345
  92. Warning: xml_parse() expects parameter 1 to be resource, int given in %s on line %d
  93. NULL
  94. Arg value 10.5
  95. Warning: xml_parse() expects parameter 1 to be resource, float given in %s on line %d
  96. NULL
  97. Arg value -10.5
  98. Warning: xml_parse() expects parameter 1 to be resource, float given in %s on line %d
  99. NULL
  100. Arg value 101234567000
  101. Warning: xml_parse() expects parameter 1 to be resource, float given in %s on line %d
  102. NULL
  103. Arg value 1.07654321E-9
  104. Warning: xml_parse() expects parameter 1 to be resource, float given in %s on line %d
  105. NULL
  106. Arg value 0.5
  107. Warning: xml_parse() expects parameter 1 to be resource, float given in %s on line %d
  108. NULL
  109. Arg value Array
  110. Warning: xml_parse() expects parameter 1 to be resource, array given in %s on line %d
  111. NULL
  112. Arg value Array
  113. Warning: xml_parse() expects parameter 1 to be resource, array given in %s on line %d
  114. NULL
  115. Arg value Array
  116. Warning: xml_parse() expects parameter 1 to be resource, array given in %s on line %d
  117. NULL
  118. Arg value Array
  119. Warning: xml_parse() expects parameter 1 to be resource, array given in %s on line %d
  120. NULL
  121. Arg value Array
  122. Warning: xml_parse() expects parameter 1 to be resource, array given in %s on line %d
  123. NULL
  124. Arg value
  125. Warning: xml_parse() expects parameter 1 to be resource, null given in %s on line %d
  126. NULL
  127. Arg value
  128. Warning: xml_parse() expects parameter 1 to be resource, null given in %s on line %d
  129. NULL
  130. Arg value 1
  131. Warning: xml_parse() expects parameter 1 to be resource, bool given in %s on line %d
  132. NULL
  133. Arg value
  134. Warning: xml_parse() expects parameter 1 to be resource, bool given in %s on line %d
  135. NULL
  136. Arg value 1
  137. Warning: xml_parse() expects parameter 1 to be resource, bool given in %s on line %d
  138. NULL
  139. Arg value
  140. Warning: xml_parse() expects parameter 1 to be resource, bool given in %s on line %d
  141. NULL
  142. Arg value
  143. Warning: xml_parse() expects parameter 1 to be resource, string given in %s on line %d
  144. NULL
  145. Arg value
  146. Warning: xml_parse() expects parameter 1 to be resource, string given in %s on line %d
  147. NULL
  148. Arg value string
  149. Warning: xml_parse() expects parameter 1 to be resource, string given in %s on line %d
  150. NULL
  151. Arg value string
  152. Warning: xml_parse() expects parameter 1 to be resource, string given in %s on line %d
  153. NULL
  154. Arg value Some Ascii Data
  155. Warning: xml_parse() expects parameter 1 to be resource, object given in %s on line %d
  156. NULL
  157. Arg value Resource id %s
  158. Warning: xml_parse(): supplied resource is not a valid XML Parser resource in %s on line %d
  159. bool(false)
  160. Arg value
  161. Warning: xml_parse() expects parameter 1 to be resource, null given in %s on line %d
  162. NULL
  163. Arg value
  164. Warning: xml_parse() expects parameter 1 to be resource, null given in %s on line %d
  165. NULL
  166. Done