xml_parser_create_variation1.phpt 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. --TEST--
  2. Test xml_parser_create() function : usage variations
  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 resource xml_parser_create([string encoding])
  12. * Description: Create an XML parser
  13. * Source code: ext/xml/xml.c
  14. * Alias to functions:
  15. */
  16. echo "*** Testing xml_parser_create() : 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. //get an unset variable
  25. $unset_var = 10;
  26. unset ($unset_var);
  27. $fp = fopen(__FILE__, "r");
  28. //array of values to iterate over
  29. $values = array(
  30. // int data
  31. 0,
  32. 1,
  33. 12345,
  34. -2345,
  35. // float data
  36. 10.5,
  37. -10.5,
  38. 10.1234567e10,
  39. 10.7654321E-10,
  40. .5,
  41. // array data
  42. array(),
  43. array(0),
  44. array(1),
  45. array(1, 2),
  46. array('color' => 'red', 'item' => 'pen'),
  47. // null data
  48. NULL,
  49. null,
  50. // boolean data
  51. true,
  52. false,
  53. TRUE,
  54. FALSE,
  55. // empty data
  56. "",
  57. '',
  58. // string data
  59. "string",
  60. 'string',
  61. "ISO-8859-1",
  62. "UTF-8",
  63. "US-ASCII",
  64. "UTF-32",
  65. // object data
  66. new aClass(),
  67. // resource data
  68. $fp,
  69. // undefined data
  70. $undefined_var,
  71. // unset data
  72. $unset_var,
  73. );
  74. // loop through each element of the array for encoding
  75. foreach($values as $value) {
  76. echo @"\nArg value $value \n";
  77. $res = xml_parser_create($value);
  78. var_dump($res);
  79. if ($res !== false) {
  80. xml_parser_free($res);
  81. }
  82. };
  83. fclose($fp);
  84. echo "Done";
  85. ?>
  86. --EXPECTF--
  87. *** Testing xml_parser_create() : usage variations ***
  88. Arg value 0
  89. Warning: xml_parser_create(): unsupported source encoding "0" in %s on line %d
  90. bool(false)
  91. Arg value 1
  92. Warning: xml_parser_create(): unsupported source encoding "1" in %s on line %d
  93. bool(false)
  94. Arg value 12345
  95. Warning: xml_parser_create(): unsupported source encoding "12345" in %s on line %d
  96. bool(false)
  97. Arg value -2345
  98. Warning: xml_parser_create(): unsupported source encoding "-2345" in %s on line %d
  99. bool(false)
  100. Arg value 10.5
  101. Warning: xml_parser_create(): unsupported source encoding "10.5" in %s on line %d
  102. bool(false)
  103. Arg value -10.5
  104. Warning: xml_parser_create(): unsupported source encoding "-10.5" in %s on line %d
  105. bool(false)
  106. Arg value 101234567000
  107. Warning: xml_parser_create(): unsupported source encoding "101234567000" in %s on line %d
  108. bool(false)
  109. Arg value 1.07654321E-9
  110. Warning: xml_parser_create(): unsupported source encoding "1.07654321E-9" in %s on line %d
  111. bool(false)
  112. Arg value 0.5
  113. Warning: xml_parser_create(): unsupported source encoding "0.5" in %s on line %d
  114. bool(false)
  115. Arg value Array
  116. Warning: xml_parser_create() expects parameter 1 to be string, array given in %s on line %d
  117. bool(false)
  118. Arg value Array
  119. Warning: xml_parser_create() expects parameter 1 to be string, array given in %s on line %d
  120. bool(false)
  121. Arg value Array
  122. Warning: xml_parser_create() expects parameter 1 to be string, array given in %s on line %d
  123. bool(false)
  124. Arg value Array
  125. Warning: xml_parser_create() expects parameter 1 to be string, array given in %s on line %d
  126. bool(false)
  127. Arg value Array
  128. Warning: xml_parser_create() expects parameter 1 to be string, array given in %s on line %d
  129. bool(false)
  130. Arg value
  131. resource(%d) of type (xml)
  132. Arg value
  133. resource(%d) of type (xml)
  134. Arg value 1
  135. Warning: xml_parser_create(): unsupported source encoding "1" in %s on line %d
  136. bool(false)
  137. Arg value
  138. resource(%d) of type (xml)
  139. Arg value 1
  140. Warning: xml_parser_create(): unsupported source encoding "1" in %s on line %d
  141. bool(false)
  142. Arg value
  143. resource(%d) of type (xml)
  144. Arg value
  145. resource(%d) of type (xml)
  146. Arg value
  147. resource(%d) of type (xml)
  148. Arg value string
  149. Warning: xml_parser_create(): unsupported source encoding "string" in %s on line %d
  150. bool(false)
  151. Arg value string
  152. Warning: xml_parser_create(): unsupported source encoding "string" in %s on line %d
  153. bool(false)
  154. Arg value ISO-8859-1
  155. resource(%d) of type (xml)
  156. Arg value UTF-8
  157. resource(%d) of type (xml)
  158. Arg value US-ASCII
  159. resource(%d) of type (xml)
  160. Arg value UTF-32
  161. Warning: xml_parser_create(): unsupported source encoding "UTF-32" in %s on line %d
  162. bool(false)
  163. Arg value Some Ascii Data
  164. Warning: xml_parser_create(): unsupported source encoding "Some Ascii Data" in %s on line %d
  165. bool(false)
  166. Arg value Resource id %s
  167. Warning: xml_parser_create() expects parameter 1 to be string, resource given in %s on line %d
  168. bool(false)
  169. Arg value
  170. resource(%d) of type (xml)
  171. Arg value
  172. resource(%d) of type (xml)
  173. Done