PageRenderTime 72ms CodeModel.GetById 40ms app.highlight 3ms RepoModel.GetById 27ms 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
 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/*
 8 * Passing non array values to 'input' argument of array_unique() and see
 9 * that the function outputs proper warning messages wherever expected.
10*/
11
12// get a class
13class classA
14{
15  public function __toString() {
16    return "Class A object";
17  }
18}
19<<__EntryPoint>> function main(): void {
20echo "*** Testing array_unique() : Passing non array values to \$input argument ***\n";
21
22//get an unset variable
23$unset_var = 10;
24unset($unset_var);
25
26// heredoc string
27$heredoc = <<<EOT
28hello world
29EOT;
30
31// get a resource variable
32$fp = fopen(__FILE__, "r");
33
34// unexpected values to be passed to $input argument
35$inputs = varray [
36
37       // int data
38/*1*/  0,
39       1,
40       12345,
41       -2345,
42
43       // float data
44/*5*/  10.5,
45       -10.5,
46       12.3456789000e10,
47       12.3456789000E-10,
48       .5,
49
50       // null data
51/*10*/ NULL,
52       null,
53
54       // boolean data
55/*12*/ true,
56       false,
57       TRUE,
58       FALSE,
59
60       // empty data
61/*16*/ "",
62       '',
63
64       // string data
65/*18*/ "string",
66       'string',
67       $heredoc,
68
69       // object data
70/*21*/ new classA(),
71
72       // undefined data
73/*22*/ @$undefined_var,
74
75       // unset data
76/*23*/ @$unset_var,
77
78       // resource variable
79/*24*/ $fp
80];
81
82// loop through each element of $inputs and check the behavior of array_unique()
83$iterator = 1;
84foreach($inputs as $input) {
85  echo "-- Iteration $iterator --\n";
86  var_dump( array_unique($input) );
87  $iterator++;
88}
89
90fclose($fp);
91
92echo "Done";
93}