array_pad_variation2.phpt 4.3 KB

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