array_fill_variation3.phpt 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. --TEST--
  2. Test array_fill() function : usage variations - unexpected values for 'val' argument
  3. --FILE--
  4. <?php
  5. /* Prototype : array array_fill(int $start_key, int $num, mixed $val)
  6. * Description: Create an array containing num elements starting with index start_key each initialized to val
  7. * Source code: ext/standard/array.c
  8. */
  9. /*
  10. * testing array_fill() by passing different unexpected values for 'val' argument
  11. */
  12. echo "*** Testing array_fill() : usage variations ***\n";
  13. // Initialise function arguments not being substituted
  14. $start_key = 0;
  15. $num = 2;
  16. //get an unset variable
  17. $unset_var = 10;
  18. unset ($unset_var);
  19. // define a class
  20. class test
  21. {
  22. var $t = 10;
  23. function __toString()
  24. {
  25. return "testObject";
  26. }
  27. }
  28. //array of different values for 'val' argument
  29. $values = array(
  30. // empty string
  31. /* 1 */ "",
  32. '',
  33. // objects
  34. /* 3 */ new test(),
  35. // undefined variable
  36. @$undefined_var,
  37. // unset variable
  38. /* 5 */ @$unset_var,
  39. );
  40. // loop through each element of the array for 'val' argument
  41. // check the working of array_fill()
  42. echo "--- Testing array_fill() with different values for 'val' argument ---\n";
  43. $counter = 1;
  44. for($index = 0; $index < count($values); $index ++)
  45. {
  46. echo "-- Iteration $counter --\n";
  47. $val = $values[$index];
  48. var_dump( array_fill($start_key , $num , $val) );
  49. $counter++;
  50. }
  51. echo"Done";
  52. ?>
  53. --EXPECTF--
  54. *** Testing array_fill() : usage variations ***
  55. --- Testing array_fill() with different values for 'val' argument ---
  56. -- Iteration 1 --
  57. array(2) {
  58. [0]=>
  59. string(0) ""
  60. [1]=>
  61. string(0) ""
  62. }
  63. -- Iteration 2 --
  64. array(2) {
  65. [0]=>
  66. string(0) ""
  67. [1]=>
  68. string(0) ""
  69. }
  70. -- Iteration 3 --
  71. array(2) {
  72. [0]=>
  73. object(test)#%d (1) {
  74. ["t"]=>
  75. int(10)
  76. }
  77. [1]=>
  78. object(test)#%d (1) {
  79. ["t"]=>
  80. int(10)
  81. }
  82. }
  83. -- Iteration 4 --
  84. array(2) {
  85. [0]=>
  86. NULL
  87. [1]=>
  88. NULL
  89. }
  90. -- Iteration 5 --
  91. array(2) {
  92. [0]=>
  93. NULL
  94. [1]=>
  95. NULL
  96. }
  97. Done