array_fill_variation1.phpt 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. --TEST--
  2. Test array_fill() function : usage variations - unexpected values for 'start_key' argument
  3. --SKIPIF--
  4. <?php
  5. if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only");
  6. ?>
  7. --FILE--
  8. <?php
  9. /* Prototype : proto array array_fill(int start_key, int num, mixed val)
  10. * Description: Create an array containing num elements starting with index start_key each initialized to val
  11. * Source code: ext/standard/array.c
  12. */
  13. /*
  14. * testing array_fill() by passing different unexpected value for 'start_key' argument
  15. */
  16. echo "*** Testing array_fill() : usage variations ***\n";
  17. // Initialise function arguments not being substituted
  18. $num = 2;
  19. $val = 100;
  20. //get an unset variable
  21. $unset_var = 10;
  22. unset ($unset_var);
  23. //get a resource variable
  24. $fp = fopen(__FILE__, "r");
  25. //define a class
  26. class test
  27. {
  28. var $t = 10;
  29. function __toString()
  30. {
  31. return "testObject";
  32. }
  33. }
  34. //array of different values for 'start_key' argument
  35. $values = array(
  36. // float values
  37. /* 1 */ 10.5,
  38. -10.5,
  39. 12.3456789000e10,
  40. 12.34567890006E-10,
  41. .5,
  42. // array values
  43. /* 6 */ array(),
  44. array(0),
  45. array(1),
  46. array(1, 2),
  47. array('color' => 'red', 'item' => 'pen'),
  48. // null values
  49. /* 11 */ NULL,
  50. null,
  51. // boolean values
  52. /* 13 */ true,
  53. false,
  54. TRUE,
  55. FALSE,
  56. // empty string
  57. /* 17 */ "",
  58. '',
  59. // string values
  60. /* 19 */ "string",
  61. 'string',
  62. // objects
  63. /* 21 */ new test(),
  64. // undefined variable
  65. @$undefined_var,
  66. // unset variable
  67. @$unset_var,
  68. // resource variable
  69. /* 24 */ $fp
  70. );
  71. // loop through each element of the array for start_key
  72. // check the working of array_fill()
  73. echo "--- Testing array_fill() with different values for 'start_key' arg ---\n";
  74. $counter = 1;
  75. for($index = 0; $index < count($values); $index ++)
  76. {
  77. echo "-- Iteration $counter --\n";
  78. $start_key = $values[$index];
  79. var_dump( array_fill($start_key,$num,$val) );
  80. $counter ++;
  81. }
  82. // close the resource used
  83. fclose($fp);
  84. echo "Done";
  85. ?>
  86. --EXPECTF--
  87. *** Testing array_fill() : usage variations ***
  88. --- Testing array_fill() with different values for 'start_key' arg ---
  89. -- Iteration 1 --
  90. array(2) {
  91. [10]=>
  92. int(100)
  93. [11]=>
  94. int(100)
  95. }
  96. -- Iteration 2 --
  97. array(2) {
  98. [-10]=>
  99. int(100)
  100. [0]=>
  101. int(100)
  102. }
  103. -- Iteration 3 --
  104. Warning: array_fill() expects parameter 1 to be int, float given in %s%eext%estandard%etests%earray%earray_fill_variation1.php on line 92
  105. NULL
  106. -- Iteration 4 --
  107. array(2) {
  108. [0]=>
  109. int(100)
  110. [1]=>
  111. int(100)
  112. }
  113. -- Iteration 5 --
  114. array(2) {
  115. [0]=>
  116. int(100)
  117. [1]=>
  118. int(100)
  119. }
  120. -- Iteration 6 --
  121. Warning: array_fill() expects parameter 1 to be int, array given in %sarray_fill_variation1.php on line %d
  122. NULL
  123. -- Iteration 7 --
  124. Warning: array_fill() expects parameter 1 to be int, array given in %sarray_fill_variation1.php on line %d
  125. NULL
  126. -- Iteration 8 --
  127. Warning: array_fill() expects parameter 1 to be int, array given in %sarray_fill_variation1.php on line %d
  128. NULL
  129. -- Iteration 9 --
  130. Warning: array_fill() expects parameter 1 to be int, array given in %sarray_fill_variation1.php on line %d
  131. NULL
  132. -- Iteration 10 --
  133. Warning: array_fill() expects parameter 1 to be int, array given in %sarray_fill_variation1.php on line %d
  134. NULL
  135. -- Iteration 11 --
  136. array(2) {
  137. [0]=>
  138. int(100)
  139. [1]=>
  140. int(100)
  141. }
  142. -- Iteration 12 --
  143. array(2) {
  144. [0]=>
  145. int(100)
  146. [1]=>
  147. int(100)
  148. }
  149. -- Iteration 13 --
  150. array(2) {
  151. [1]=>
  152. int(100)
  153. [2]=>
  154. int(100)
  155. }
  156. -- Iteration 14 --
  157. array(2) {
  158. [0]=>
  159. int(100)
  160. [1]=>
  161. int(100)
  162. }
  163. -- Iteration 15 --
  164. array(2) {
  165. [1]=>
  166. int(100)
  167. [2]=>
  168. int(100)
  169. }
  170. -- Iteration 16 --
  171. array(2) {
  172. [0]=>
  173. int(100)
  174. [1]=>
  175. int(100)
  176. }
  177. -- Iteration 17 --
  178. Warning: array_fill() expects parameter 1 to be int, string given in %sarray_fill_variation1.php on line %d
  179. NULL
  180. -- Iteration 18 --
  181. Warning: array_fill() expects parameter 1 to be int, string given in %sarray_fill_variation1.php on line %d
  182. NULL
  183. -- Iteration 19 --
  184. Warning: array_fill() expects parameter 1 to be int, string given in %sarray_fill_variation1.php on line %d
  185. NULL
  186. -- Iteration 20 --
  187. Warning: array_fill() expects parameter 1 to be int, string given in %sarray_fill_variation1.php on line %d
  188. NULL
  189. -- Iteration 21 --
  190. Warning: array_fill() expects parameter 1 to be int, object given in %sarray_fill_variation1.php on line %d
  191. NULL
  192. -- Iteration 22 --
  193. array(2) {
  194. [0]=>
  195. int(100)
  196. [1]=>
  197. int(100)
  198. }
  199. -- Iteration 23 --
  200. array(2) {
  201. [0]=>
  202. int(100)
  203. [1]=>
  204. int(100)
  205. }
  206. -- Iteration 24 --
  207. Warning: array_fill() expects parameter 1 to be int, resource given in %sarray_fill_variation1.php on line %d
  208. NULL
  209. Done