array_shift_variation2.phpt 3.0 KB

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