array_shift_variation3.phpt 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. --TEST--
  2. Test array_shift() function : usage variations - Pass array with different data types as keys
  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 with different data types as keys to test how array_shift() re-assigns keys
  11. */
  12. echo "*** Testing array_shift() : usage variations ***\n";
  13. //get an unset variable
  14. $unset_var = 10;
  15. unset ($unset_var);
  16. // heredoc string
  17. $heredoc = <<<EOT
  18. hello world
  19. EOT;
  20. // unexpected values to be passed to $stack argument
  21. $inputs = array(
  22. // int data
  23. /*1*/ 'int' => array(
  24. 0 => 'zero',
  25. 1 => 'one',
  26. 12345 => 'positive',
  27. -2345 => 'negative',
  28. ),
  29. // float data
  30. /*2*/ 'float' => array(
  31. 10.5 => 'positive',
  32. -10.5 => 'negative',
  33. .5 => 'half',
  34. ),
  35. /*3*/ 'extreme floats' => array(
  36. 12.3456789000e10 => 'large',
  37. 12.3456789000E-10 => 'small',
  38. ),
  39. // null data
  40. /*4*/ 'null uppercase' => array(
  41. NULL => 'null 1',
  42. ),
  43. /*5*/ 'null lowercase' => array(
  44. null => 'null 2',
  45. ),
  46. // boolean data
  47. /*6*/ 'bool lowercase' => array(
  48. true => 'lowert',
  49. false => 'lowerf',
  50. ),
  51. /*7*/ 'bool uppercase' => array(
  52. TRUE => 'uppert',
  53. FALSE => 'upperf',
  54. ),
  55. // empty data
  56. /*8*/ 'empty double quotes' => array(
  57. "" => 'emptyd',
  58. ),
  59. /*9*/ 'empty single quotes' => array(
  60. '' => 'emptys',
  61. ),
  62. // string data
  63. /*10*/ 'string' => array(
  64. "stringd" => 'stringd',
  65. 'strings' => 'strings',
  66. $heredoc => 'stringh',
  67. ),
  68. // undefined data
  69. /*11*/ 'undefined' => array(
  70. @$undefined_var => 'undefined',
  71. ),
  72. // unset data
  73. /*12*/ 'unset' => array(
  74. @$unset_var => 'unset',
  75. ),
  76. );
  77. // loop through each element of $inputs to check the behavior of array_shift()
  78. $iterator = 1;
  79. foreach($inputs as $key => $input) {
  80. echo "\n-- Iteration $iterator : $key data --\n";
  81. var_dump( array_shift($input) );
  82. var_dump($input);
  83. $iterator++;
  84. };
  85. echo "Done";
  86. ?>
  87. --EXPECTF--
  88. *** Testing array_shift() : usage variations ***
  89. -- Iteration 1 : int data --
  90. string(4) "zero"
  91. array(3) {
  92. [0]=>
  93. string(3) "one"
  94. [1]=>
  95. string(8) "positive"
  96. [2]=>
  97. string(8) "negative"
  98. }
  99. -- Iteration 2 : float data --
  100. string(8) "positive"
  101. array(2) {
  102. [0]=>
  103. string(8) "negative"
  104. [1]=>
  105. string(4) "half"
  106. }
  107. -- Iteration 3 : extreme floats data --
  108. string(5) "large"
  109. array(1) {
  110. [0]=>
  111. string(5) "small"
  112. }
  113. -- Iteration 4 : null uppercase data --
  114. string(6) "null 1"
  115. array(0) {
  116. }
  117. -- Iteration 5 : null lowercase data --
  118. string(6) "null 2"
  119. array(0) {
  120. }
  121. -- Iteration 6 : bool lowercase data --
  122. string(6) "lowert"
  123. array(1) {
  124. [0]=>
  125. string(6) "lowerf"
  126. }
  127. -- Iteration 7 : bool uppercase data --
  128. string(6) "uppert"
  129. array(1) {
  130. [0]=>
  131. string(6) "upperf"
  132. }
  133. -- Iteration 8 : empty double quotes data --
  134. string(6) "emptyd"
  135. array(0) {
  136. }
  137. -- Iteration 9 : empty single quotes data --
  138. string(6) "emptys"
  139. array(0) {
  140. }
  141. -- Iteration 10 : string data --
  142. string(7) "stringd"
  143. array(2) {
  144. ["strings"]=>
  145. string(7) "strings"
  146. ["hello world"]=>
  147. string(7) "stringh"
  148. }
  149. -- Iteration 11 : undefined data --
  150. string(9) "undefined"
  151. array(0) {
  152. }
  153. -- Iteration 12 : unset data --
  154. string(5) "unset"
  155. array(0) {
  156. }
  157. Done