array_pad_variation2.phpt 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. --TEST--
  2. Test array_pad() function : usage variations - unexpected values for 'pad_size' argument(Bug#43482)
  3. --FILE--
  4. <?php
  5. /* Prototype : array array_pad(array $input, int $pad_size, mixed $pad_value)
  6. * Description: Returns a copy of input array padded with pad_value to size pad_size
  7. * Source code: ext/standard/array.c
  8. */
  9. /*
  10. * Testing array_pad() function by passing values to $pad_size argument other than integers
  11. * and see that function outputs proper warning messages wherever expected.
  12. * The $input and $pad_value arguments passed are fixed values.
  13. */
  14. echo "*** Testing array_pad() : passing non integer values to \$pad_size argument ***\n";
  15. // Initialise $input and $pad_value arguments
  16. $input = array(1, 2);
  17. $pad_value = 1;
  18. //get an unset variable
  19. $unset_var = 10;
  20. unset ($unset_var);
  21. // get a class
  22. class classA
  23. {
  24. public function __toString() {
  25. return "Class A object";
  26. }
  27. }
  28. //array of values to iterate over
  29. $pad_sizes = array(
  30. // float data
  31. /*1*/ 10.5,
  32. -10.5,
  33. 12.3456789000e10,
  34. -12.3456789000e10,
  35. 12.3456789000E-10,
  36. .5,
  37. // array data
  38. /*6*/ array(),
  39. array(0),
  40. array(1),
  41. array(1, 2),
  42. array('color' => 'red', 'item' => 'pen'),
  43. // null data
  44. /*11*/ NULL,
  45. null,
  46. // boolean data
  47. /*13*/ true,
  48. false,
  49. TRUE,
  50. FALSE,
  51. // empty data
  52. /*17*/ "",
  53. '',
  54. // string data
  55. /*19*/ "string",
  56. 'string',
  57. // object data
  58. /*21*/ new classA(),
  59. // undefined data
  60. /*22*/ @$undefined_var,
  61. // unset data
  62. /*23*/ @$unset_var,
  63. );
  64. // loop through each element of $pad_sizes to check the behavior of array_pad()
  65. $iterator = 1;
  66. foreach($pad_sizes as $pad_size) {
  67. echo "-- Iteration $iterator --\n";
  68. var_dump( array_pad($input, $pad_size, $pad_value) );
  69. $iterator++;
  70. };
  71. echo "Done";
  72. ?>
  73. --EXPECTF--
  74. *** Testing array_pad() : passing non integer values to $pad_size argument ***
  75. -- Iteration 1 --
  76. array(10) {
  77. [0]=>
  78. int(1)
  79. [1]=>
  80. int(2)
  81. [2]=>
  82. int(1)
  83. [3]=>
  84. int(1)
  85. [4]=>
  86. int(1)
  87. [5]=>
  88. int(1)
  89. [6]=>
  90. int(1)
  91. [7]=>
  92. int(1)
  93. [8]=>
  94. int(1)
  95. [9]=>
  96. int(1)
  97. }
  98. -- Iteration 2 --
  99. array(10) {
  100. [0]=>
  101. int(1)
  102. [1]=>
  103. int(1)
  104. [2]=>
  105. int(1)
  106. [3]=>
  107. int(1)
  108. [4]=>
  109. int(1)
  110. [5]=>
  111. int(1)
  112. [6]=>
  113. int(1)
  114. [7]=>
  115. int(1)
  116. [8]=>
  117. int(1)
  118. [9]=>
  119. int(2)
  120. }
  121. -- Iteration 3 --
  122. Warning: array_pad(): You may only pad up to 1048576 elements at a time in %s on line %d
  123. bool(false)
  124. -- Iteration 4 --
  125. Warning: array_pad(): You may only pad up to 1048576 elements at a time in %s on line %d
  126. bool(false)
  127. -- Iteration 5 --
  128. array(2) {
  129. [0]=>
  130. int(1)
  131. [1]=>
  132. int(2)
  133. }
  134. -- Iteration 6 --
  135. array(2) {
  136. [0]=>
  137. int(1)
  138. [1]=>
  139. int(2)
  140. }
  141. -- Iteration 7 --
  142. Warning: array_pad() expects parameter 2 to be long, array given in %s on line %d
  143. NULL
  144. -- Iteration 8 --
  145. Warning: array_pad() expects parameter 2 to be long, array given in %s on line %d
  146. NULL
  147. -- Iteration 9 --
  148. Warning: array_pad() expects parameter 2 to be long, array given in %s on line %d
  149. NULL
  150. -- Iteration 10 --
  151. Warning: array_pad() expects parameter 2 to be long, array given in %s on line %d
  152. NULL
  153. -- Iteration 11 --
  154. Warning: array_pad() expects parameter 2 to be long, array given in %s on line %d
  155. NULL
  156. -- Iteration 12 --
  157. array(2) {
  158. [0]=>
  159. int(1)
  160. [1]=>
  161. int(2)
  162. }
  163. -- Iteration 13 --
  164. array(2) {
  165. [0]=>
  166. int(1)
  167. [1]=>
  168. int(2)
  169. }
  170. -- Iteration 14 --
  171. array(2) {
  172. [0]=>
  173. int(1)
  174. [1]=>
  175. int(2)
  176. }
  177. -- Iteration 15 --
  178. array(2) {
  179. [0]=>
  180. int(1)
  181. [1]=>
  182. int(2)
  183. }
  184. -- Iteration 16 --
  185. array(2) {
  186. [0]=>
  187. int(1)
  188. [1]=>
  189. int(2)
  190. }
  191. -- Iteration 17 --
  192. array(2) {
  193. [0]=>
  194. int(1)
  195. [1]=>
  196. int(2)
  197. }
  198. -- Iteration 18 --
  199. Warning: array_pad() expects parameter 2 to be long, string given in %s on line %d
  200. NULL
  201. -- Iteration 19 --
  202. Warning: array_pad() expects parameter 2 to be long, string given in %s on line %d
  203. NULL
  204. -- Iteration 20 --
  205. Warning: array_pad() expects parameter 2 to be long, string given in %s on line %d
  206. NULL
  207. -- Iteration 21 --
  208. Warning: array_pad() expects parameter 2 to be long, string given in %s on line %d
  209. NULL
  210. -- Iteration 22 --
  211. Warning: array_pad() expects parameter 2 to be long, object given in %s on line %d
  212. NULL
  213. -- Iteration 23 --
  214. array(2) {
  215. [0]=>
  216. int(1)
  217. [1]=>
  218. int(2)
  219. }
  220. -- Iteration 24 --
  221. array(2) {
  222. [0]=>
  223. int(1)
  224. [1]=>
  225. int(2)
  226. }
  227. Done