array_unique_variation1.phpt 4.4 KB

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