array_push_variation1.phpt 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. --TEST--
  2. Test array_push() function : usage variations - Pass different data types as $stack arg
  3. --FILE--
  4. <?php
  5. /* Prototype : int array_push(array $stack, mixed $var [, mixed $...])
  6. * Description: Pushes elements onto the end of the array
  7. * Source code: ext/standard/array.c
  8. */
  9. /*
  10. * Pass different data types as $stack argument to array_push() to test behaviour
  11. */
  12. echo "*** Testing array_push() : usage variations ***\n";
  13. // Initialise function arguments not being substituted
  14. $var = 'value';
  15. //get an unset variable
  16. $unset_var = 10;
  17. unset ($unset_var);
  18. // get a class
  19. class classA
  20. {
  21. public function __toString() {
  22. return "Class A object";
  23. }
  24. }
  25. // heredoc string
  26. $heredoc = <<<EOT
  27. hello world
  28. EOT;
  29. // get a resource variable
  30. $fp = fopen(__FILE__, "r");
  31. // unexpected values to be passed to $stack argument
  32. $inputs = array(
  33. // int data
  34. /*1*/ 0,
  35. 1,
  36. 12345,
  37. -2345,
  38. // float data
  39. /*5*/ 10.5,
  40. -10.5,
  41. 12.3456789000e10,
  42. 12.3456789000E-10,
  43. .5,
  44. // null data
  45. /*10*/ NULL,
  46. null,
  47. // boolean data
  48. /*12*/ true,
  49. false,
  50. TRUE,
  51. FALSE,
  52. // empty data
  53. /*16*/ "",
  54. '',
  55. array(),
  56. // string data
  57. /*19*/ "string",
  58. 'string',
  59. $heredoc,
  60. // object data
  61. /*22*/ new classA(),
  62. // undefined data
  63. /*23*/ @$undefined_var,
  64. // unset data
  65. /*24*/ @$unset_var,
  66. // resource variable
  67. /*25*/ $fp
  68. );
  69. // loop through each element of $inputs to check the behavior of array_push()
  70. $iterator = 1;
  71. foreach($inputs as $input) {
  72. echo "\n-- Iteration $iterator --\n";
  73. var_dump( array_push($input, $var) );
  74. $iterator++;
  75. };
  76. fclose($fp);
  77. echo "Done";
  78. ?>
  79. --EXPECTF--
  80. *** Testing array_push() : usage variations ***
  81. -- Iteration 1 --
  82. Warning: array_push() expects parameter 1 to be array, integer given in %s on line %d
  83. NULL
  84. -- Iteration 2 --
  85. Warning: array_push() expects parameter 1 to be array, integer given in %s on line %d
  86. NULL
  87. -- Iteration 3 --
  88. Warning: array_push() expects parameter 1 to be array, integer given in %s on line %d
  89. NULL
  90. -- Iteration 4 --
  91. Warning: array_push() expects parameter 1 to be array, integer given in %s on line %d
  92. NULL
  93. -- Iteration 5 --
  94. Warning: array_push() expects parameter 1 to be array, double given in %s on line %d
  95. NULL
  96. -- Iteration 6 --
  97. Warning: array_push() expects parameter 1 to be array, double given in %s on line %d
  98. NULL
  99. -- Iteration 7 --
  100. Warning: array_push() expects parameter 1 to be array, double given in %s on line %d
  101. NULL
  102. -- Iteration 8 --
  103. Warning: array_push() expects parameter 1 to be array, double given in %s on line %d
  104. NULL
  105. -- Iteration 9 --
  106. Warning: array_push() expects parameter 1 to be array, double given in %s on line %d
  107. NULL
  108. -- Iteration 10 --
  109. Warning: array_push() expects parameter 1 to be array, null given in %s on line %d
  110. NULL
  111. -- Iteration 11 --
  112. Warning: array_push() expects parameter 1 to be array, null given in %s on line %d
  113. NULL
  114. -- Iteration 12 --
  115. Warning: array_push() expects parameter 1 to be array, boolean given in %s on line %d
  116. NULL
  117. -- Iteration 13 --
  118. Warning: array_push() expects parameter 1 to be array, boolean given in %s on line %d
  119. NULL
  120. -- Iteration 14 --
  121. Warning: array_push() expects parameter 1 to be array, boolean given in %s on line %d
  122. NULL
  123. -- Iteration 15 --
  124. Warning: array_push() expects parameter 1 to be array, boolean given in %s on line %d
  125. NULL
  126. -- Iteration 16 --
  127. Warning: array_push() expects parameter 1 to be array, string given in %s on line %d
  128. NULL
  129. -- Iteration 17 --
  130. Warning: array_push() expects parameter 1 to be array, string given in %s on line %d
  131. NULL
  132. -- Iteration 18 --
  133. int(1)
  134. -- Iteration 19 --
  135. Warning: array_push() expects parameter 1 to be array, string given in %s on line %d
  136. NULL
  137. -- Iteration 20 --
  138. Warning: array_push() expects parameter 1 to be array, string given in %s on line %d
  139. NULL
  140. -- Iteration 21 --
  141. Warning: array_push() expects parameter 1 to be array, string given in %s on line %d
  142. NULL
  143. -- Iteration 22 --
  144. Warning: array_push() expects parameter 1 to be array, object given in %s on line %d
  145. NULL
  146. -- Iteration 23 --
  147. Warning: array_push() expects parameter 1 to be array, null given in %s on line %d
  148. NULL
  149. -- Iteration 24 --
  150. Warning: array_push() expects parameter 1 to be array, null given in %s on line %d
  151. NULL
  152. -- Iteration 25 --
  153. Warning: array_push() expects parameter 1 to be array, resource given in %s on line %d
  154. NULL
  155. Done