array_walk_variation2.phpt 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. --TEST--
  2. Test array_walk() function : usage variations - unexpected values in place of 'funcname' argument
  3. --FILE--
  4. <?php
  5. /* Prototype : bool array_walk(array $input, string $funcname [, mixed $userdata])
  6. * Description: Apply a user function to every member of an array
  7. * Source code: ext/standard/array.c
  8. */
  9. /*
  10. * Passing different scalar/nonscalar values in place of 'funcname' argument
  11. */
  12. echo "*** Testing array_walk() : unexpected values for 'funcname' argument ***\n";
  13. $input = array(1, 2);
  14. //get an unset variable
  15. $unset_var = 10;
  16. unset ($unset_var);
  17. $user_data = 20;
  18. // class definition
  19. class MyClass
  20. {
  21. public function __toString()
  22. {
  23. return 'object';
  24. }
  25. }
  26. // different scalar/nonscalar values to be used in place of callback function
  27. $funcname_values = array(
  28. // int data
  29. /* 1*/ 0,
  30. 1,
  31. 12345,
  32. -2345,
  33. // float data
  34. /* 5*/ 10.5,
  35. -10.5,
  36. 10.1234567e8,
  37. 10.7654321E-8,
  38. .5,
  39. // array data
  40. /* 10*/ array(),
  41. array(0),
  42. array(1),
  43. array('color' => 'red', 'item' => 'pen'),
  44. // null data
  45. /* 14*/ NULL,
  46. null,
  47. // boolean data
  48. /* 16*/ true,
  49. false,
  50. TRUE,
  51. FALSE,
  52. // empty data
  53. /* 20*/ "",
  54. '',
  55. // object data
  56. new MyClass(),
  57. // resource data
  58. /* 23*/ $fp = fopen(__FILE__, 'r'),
  59. // undefined data
  60. @$undefined_var,
  61. // unset data
  62. /* 25*/ @$unset_var,
  63. );
  64. for($count = 0; $count < count($funcname_values); $count++) {
  65. echo "-- Iteration ".($count + 1)." --\n";
  66. var_dump( array_walk($input, $funcname_values[$count]) );
  67. var_dump( array_walk($input, $funcname_values[$count], $user_data ));
  68. }
  69. fclose($fp);
  70. echo "Done"
  71. ?>
  72. --EXPECTF--
  73. *** Testing array_walk() : unexpected values for 'funcname' argument ***
  74. -- Iteration 1 --
  75. Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d
  76. NULL
  77. Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d
  78. NULL
  79. -- Iteration 2 --
  80. Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d
  81. NULL
  82. Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d
  83. NULL
  84. -- Iteration 3 --
  85. Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d
  86. NULL
  87. Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d
  88. NULL
  89. -- Iteration 4 --
  90. Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d
  91. NULL
  92. Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d
  93. NULL
  94. -- Iteration 5 --
  95. Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d
  96. NULL
  97. Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d
  98. NULL
  99. -- Iteration 6 --
  100. Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d
  101. NULL
  102. Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d
  103. NULL
  104. -- Iteration 7 --
  105. Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d
  106. NULL
  107. Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d
  108. NULL
  109. -- Iteration 8 --
  110. Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d
  111. NULL
  112. Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d
  113. NULL
  114. -- Iteration 9 --
  115. Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d
  116. NULL
  117. Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d
  118. NULL
  119. -- Iteration 10 --
  120. Warning: array_walk() expects parameter 2 to be a valid callback, array must have exactly two members in %s on line %d
  121. NULL
  122. Warning: array_walk() expects parameter 2 to be a valid callback, array must have exactly two members in %s on line %d
  123. NULL
  124. -- Iteration 11 --
  125. Warning: array_walk() expects parameter 2 to be a valid callback, array must have exactly two members in %s on line %d
  126. NULL
  127. Warning: array_walk() expects parameter 2 to be a valid callback, array must have exactly two members in %s on line %d
  128. NULL
  129. -- Iteration 12 --
  130. Warning: array_walk() expects parameter 2 to be a valid callback, array must have exactly two members in %s on line %d
  131. NULL
  132. Warning: array_walk() expects parameter 2 to be a valid callback, array must have exactly two members in %s on line %d
  133. NULL
  134. -- Iteration 13 --
  135. Warning: array_walk() expects parameter 2 to be a valid callback, first array member is not a valid class name or object in %s on line %d
  136. NULL
  137. Warning: array_walk() expects parameter 2 to be a valid callback, first array member is not a valid class name or object in %s on line %d
  138. NULL
  139. -- Iteration 14 --
  140. Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d
  141. NULL
  142. Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d
  143. NULL
  144. -- Iteration 15 --
  145. Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d
  146. NULL
  147. Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d
  148. NULL
  149. -- Iteration 16 --
  150. Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d
  151. NULL
  152. Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d
  153. NULL
  154. -- Iteration 17 --
  155. Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d
  156. NULL
  157. Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d
  158. NULL
  159. -- Iteration 18 --
  160. Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d
  161. NULL
  162. Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d
  163. NULL
  164. -- Iteration 19 --
  165. Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d
  166. NULL
  167. Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d
  168. NULL
  169. -- Iteration 20 --
  170. Warning: array_walk() expects parameter 2 to be a valid callback, function '' not found or invalid function name in %s on line %d
  171. NULL
  172. Warning: array_walk() expects parameter 2 to be a valid callback, function '' not found or invalid function name in %s on line %d
  173. NULL
  174. -- Iteration 21 --
  175. Warning: array_walk() expects parameter 2 to be a valid callback, function '' not found or invalid function name in %s on line %d
  176. NULL
  177. Warning: array_walk() expects parameter 2 to be a valid callback, function '' not found or invalid function name in %s on line %d
  178. NULL
  179. -- Iteration 22 --
  180. Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d
  181. NULL
  182. Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d
  183. NULL
  184. -- Iteration 23 --
  185. Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d
  186. NULL
  187. Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d
  188. NULL
  189. -- Iteration 24 --
  190. Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d
  191. NULL
  192. Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d
  193. NULL
  194. -- Iteration 25 --
  195. Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d
  196. NULL
  197. Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d
  198. NULL
  199. Done