array_pad_variation1.phpt 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. --TEST--
  2. Test array_pad() function : usage variations - unexpected values for 'input' argument
  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 $input argument other than arrays
  11. * and see that function outputs proper warning messages wherever expected.
  12. * The $pad_size and $pad_value arguments passed are fixed values.
  13. */
  14. echo "*** Testing array_pad() : passing non array values to \$input argument ***\n";
  15. // Initialise $pad_size and $pad_value
  16. $pad_size = 10;
  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. // heredoc string
  29. $heredoc = <<<EOT
  30. hello world
  31. EOT;
  32. // get a resource variable
  33. $fp = fopen(__FILE__, "r");
  34. // unexpected values to be passed to $input argument
  35. $inputs = array(
  36. // int data
  37. /*1*/ 0,
  38. 1,
  39. 12345,
  40. -2345,
  41. // float data
  42. /*5*/ 10.5,
  43. -10.5,
  44. 12.3456789000e10,
  45. 12.3456789000E-10,
  46. .5,
  47. // null data
  48. /*10*/ NULL,
  49. null,
  50. // boolean data
  51. /*12*/ true,
  52. false,
  53. TRUE,
  54. FALSE,
  55. // empty data
  56. /*16*/ "",
  57. '',
  58. // string data
  59. /*18*/ "string",
  60. 'string',
  61. $heredoc,
  62. // object data
  63. /*21*/ new classA(),
  64. // undefined data
  65. /*22*/ @$undefined_var,
  66. // unset data
  67. /*23*/ @$unset_var,
  68. // resource variable
  69. /*24*/ $fp
  70. );
  71. // loop through each element of $inputs to check the behavior of array_pad()
  72. $iterator = 1;
  73. foreach($inputs as $input) {
  74. echo "\n-- Iteration $iterator --";
  75. var_dump( array_pad($input, $pad_size, $pad_value) ); // positive 'pad_size'
  76. var_dump( array_pad($input, -$pad_size, $pad_value) ); // negative 'pad_size'
  77. $iterator++;
  78. };
  79. echo "Done";
  80. ?>
  81. --EXPECTF--
  82. *** Testing array_pad() : passing non array values to $input argument ***
  83. -- Iteration 1 --
  84. Warning: array_pad() expects parameter 1 to be array, integer given in %s on line %d
  85. NULL
  86. Warning: array_pad() expects parameter 1 to be array, integer given in %s on line %d
  87. NULL
  88. -- Iteration 2 --
  89. Warning: array_pad() expects parameter 1 to be array, integer given in %s on line %d
  90. NULL
  91. Warning: array_pad() expects parameter 1 to be array, integer given in %s on line %d
  92. NULL
  93. -- Iteration 3 --
  94. Warning: array_pad() expects parameter 1 to be array, integer given in %s on line %d
  95. NULL
  96. Warning: array_pad() expects parameter 1 to be array, integer given in %s on line %d
  97. NULL
  98. -- Iteration 4 --
  99. Warning: array_pad() expects parameter 1 to be array, integer given in %s on line %d
  100. NULL
  101. Warning: array_pad() expects parameter 1 to be array, integer given in %s on line %d
  102. NULL
  103. -- Iteration 5 --
  104. Warning: array_pad() expects parameter 1 to be array, double given in %s on line %d
  105. NULL
  106. Warning: array_pad() expects parameter 1 to be array, double given in %s on line %d
  107. NULL
  108. -- Iteration 6 --
  109. Warning: array_pad() expects parameter 1 to be array, double given in %s on line %d
  110. NULL
  111. Warning: array_pad() expects parameter 1 to be array, double given in %s on line %d
  112. NULL
  113. -- Iteration 7 --
  114. Warning: array_pad() expects parameter 1 to be array, double given in %s on line %d
  115. NULL
  116. Warning: array_pad() expects parameter 1 to be array, double given in %s on line %d
  117. NULL
  118. -- Iteration 8 --
  119. Warning: array_pad() expects parameter 1 to be array, double given in %s on line %d
  120. NULL
  121. Warning: array_pad() expects parameter 1 to be array, double given in %s on line %d
  122. NULL
  123. -- Iteration 9 --
  124. Warning: array_pad() expects parameter 1 to be array, double given in %s on line %d
  125. NULL
  126. Warning: array_pad() expects parameter 1 to be array, double given in %s on line %d
  127. NULL
  128. -- Iteration 10 --
  129. Warning: array_pad() expects parameter 1 to be array, null given in %s on line %d
  130. NULL
  131. Warning: array_pad() expects parameter 1 to be array, null given in %s on line %d
  132. NULL
  133. -- Iteration 11 --
  134. Warning: array_pad() expects parameter 1 to be array, null given in %s on line %d
  135. NULL
  136. Warning: array_pad() expects parameter 1 to be array, null given in %s on line %d
  137. NULL
  138. -- Iteration 12 --
  139. Warning: array_pad() expects parameter 1 to be array, boolean given in %s on line %d
  140. NULL
  141. Warning: array_pad() expects parameter 1 to be array, boolean given in %s on line %d
  142. NULL
  143. -- Iteration 13 --
  144. Warning: array_pad() expects parameter 1 to be array, boolean given in %s on line %d
  145. NULL
  146. Warning: array_pad() expects parameter 1 to be array, boolean given in %s on line %d
  147. NULL
  148. -- Iteration 14 --
  149. Warning: array_pad() expects parameter 1 to be array, boolean given in %s on line %d
  150. NULL
  151. Warning: array_pad() expects parameter 1 to be array, boolean given in %s on line %d
  152. NULL
  153. -- Iteration 15 --
  154. Warning: array_pad() expects parameter 1 to be array, boolean given in %s on line %d
  155. NULL
  156. Warning: array_pad() expects parameter 1 to be array, boolean given in %s on line %d
  157. NULL
  158. -- Iteration 16 --
  159. Warning: array_pad() expects parameter 1 to be array, string given in %s on line %d
  160. NULL
  161. Warning: array_pad() expects parameter 1 to be array, string given in %s on line %d
  162. NULL
  163. -- Iteration 17 --
  164. Warning: array_pad() expects parameter 1 to be array, string given in %s on line %d
  165. NULL
  166. Warning: array_pad() expects parameter 1 to be array, string given in %s on line %d
  167. NULL
  168. -- Iteration 18 --
  169. Warning: array_pad() expects parameter 1 to be array, string given in %s on line %d
  170. NULL
  171. Warning: array_pad() expects parameter 1 to be array, string given in %s on line %d
  172. NULL
  173. -- Iteration 19 --
  174. Warning: array_pad() expects parameter 1 to be array, string given in %s on line %d
  175. NULL
  176. Warning: array_pad() expects parameter 1 to be array, string given in %s on line %d
  177. NULL
  178. -- Iteration 20 --
  179. Warning: array_pad() expects parameter 1 to be array, string given in %s on line %d
  180. NULL
  181. Warning: array_pad() expects parameter 1 to be array, string given in %s on line %d
  182. NULL
  183. -- Iteration 21 --
  184. Warning: array_pad() expects parameter 1 to be array, object given in %s on line %d
  185. NULL
  186. Warning: array_pad() expects parameter 1 to be array, object given in %s on line %d
  187. NULL
  188. -- Iteration 22 --
  189. Warning: array_pad() expects parameter 1 to be array, null given in %s on line %d
  190. NULL
  191. Warning: array_pad() expects parameter 1 to be array, null given in %s on line %d
  192. NULL
  193. -- Iteration 23 --
  194. Warning: array_pad() expects parameter 1 to be array, null given in %s on line %d
  195. NULL
  196. Warning: array_pad() expects parameter 1 to be array, null given in %s on line %d
  197. NULL
  198. -- Iteration 24 --
  199. Warning: array_pad() expects parameter 1 to be array, resource given in %s on line %d
  200. NULL
  201. Warning: array_pad() expects parameter 1 to be array, resource given in %s on line %d
  202. NULL
  203. Done