PageRenderTime 39ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/hphp/test/zend/good/ext/standard/tests/array/array_unique_variation1.php

http://github.com/facebook/hiphop-php
PHP | 93 lines | 50 code | 19 blank | 24 comment | 0 complexity | bf301b45b69b50f8a7dff0a35e0fe470 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-2-Clause, BSD-3-Clause, MPL-2.0-no-copyleft-exception, MIT, LGPL-2.0, Apache-2.0
  1. <?hh
  2. /* Prototype : array array_unique(array $input)
  3. * Description: Removes duplicate values from array
  4. * Source code: ext/standard/array.c
  5. */
  6. /*
  7. * Passing non array values to 'input' argument of array_unique() and see
  8. * that the function outputs proper warning messages wherever expected.
  9. */
  10. // get a class
  11. class classA
  12. {
  13. public function __toString() {
  14. return "Class A object";
  15. }
  16. }
  17. <<__EntryPoint>> function main(): void {
  18. echo "*** Testing array_unique() : Passing non array values to \$input argument ***\n";
  19. //get an unset variable
  20. $unset_var = 10;
  21. unset($unset_var);
  22. // heredoc string
  23. $heredoc = <<<EOT
  24. hello world
  25. EOT;
  26. // get a resource variable
  27. $fp = fopen(__FILE__, "r");
  28. // unexpected values to be passed to $input argument
  29. $inputs = varray [
  30. // int data
  31. /*1*/ 0,
  32. 1,
  33. 12345,
  34. -2345,
  35. // float data
  36. /*5*/ 10.5,
  37. -10.5,
  38. 12.3456789000e10,
  39. 12.3456789000E-10,
  40. .5,
  41. // null data
  42. /*10*/ NULL,
  43. null,
  44. // boolean data
  45. /*12*/ true,
  46. false,
  47. TRUE,
  48. FALSE,
  49. // empty data
  50. /*16*/ "",
  51. '',
  52. // string data
  53. /*18*/ "string",
  54. 'string',
  55. $heredoc,
  56. // object data
  57. /*21*/ new classA(),
  58. // undefined data
  59. /*22*/ @$undefined_var,
  60. // unset data
  61. /*23*/ @$unset_var,
  62. // resource variable
  63. /*24*/ $fp
  64. ];
  65. // loop through each element of $inputs and check the behavior of array_unique()
  66. $iterator = 1;
  67. foreach($inputs as $input) {
  68. echo "-- Iteration $iterator --\n";
  69. var_dump( array_unique($input) );
  70. $iterator++;
  71. }
  72. fclose($fp);
  73. echo "Done";
  74. }