Replace mixed array literals manually
[hiphop-php.git] / hphp / test / zend / good / ext / standard / tests / array / array_intersect_variation1.php
blobf6b4f651459142c4eab9d903afc6804972a7e851
1 <?hh
2 /* Prototype : array array_intersect(array $arr1, array $arr2 [, array $...])
3 * Description: Returns the entries of arr1 that have values which are present in all the other arguments
4 * Source code: ext/standard/array.c
5 */
7 /*
8 * Testing array_intersect() function by passing values to $arr1 argument other than arrays
9 * and see that function emits proper warning messages wherever expected.
10 * The $arr2 argument is a fixed array.
13 // get a class
14 class classA
16 public function __toString() {
17 return "Class A object";
20 <<__EntryPoint>> function main(): void {
21 echo "*** Testing array_intersect() : Passing non-array values to \$arr1 argument ***\n";
23 // array to be passsed to $arr2 as default argument
24 $arr2 = varray[1, 2];
26 // array to be passed to optional argument
27 $arr3 = darray[0 => 1, 1 => 2, "one" => 1, "two" => 2];
29 // get an unset variable
30 $unset_var = 10;
31 unset ($unset_var);
33 // heredoc string
34 $heredoc = <<<EOT
35 hello world
36 EOT;
38 // get a resource variable
39 $fp = fopen(__FILE__, "r");
41 // unexpected values to be passed to $arr1 argument
42 $arrays = varray[
44 // int data
45 /*1*/ 0,
47 12345,
48 -2345,
50 // float data
51 /*5*/ 10.5,
52 -10.5,
53 12.3456789000e10,
54 12.3456789000E-10,
55 .5,
57 // null data
58 /*10*/ NULL,
59 null,
61 // boolean data
62 /*12*/ true,
63 false,
64 TRUE,
65 FALSE,
67 // empty data
68 /*16*/ "",
69 '',
71 // string data
72 /*18*/ "string",
73 'string',
74 $heredoc,
76 // object data
77 /*21*/ new classA(),
79 // undefined data
80 /*22*/ @$undefined_var,
82 // unset data
83 /*23*/ @$unset_var,
85 // resource variable
86 /*24*/ $fp
89 // loop through each sub-array within $arrrays to check the behavior of array_intersect()
90 $iterator = 1;
91 foreach($arrays as $unexpected_value) {
92 echo "\n-- Iterator $iterator --";
94 // Calling array_intersect() with default arguments
95 var_dump( array_intersect($unexpected_value,$arr2) );
97 // Calling array_intersect() with more arguments
98 var_dump( array_intersect($unexpected_value, $arr2, $arr3) );
99 $iterator++;
102 // close the file resource used
103 fclose($fp);
105 echo "Done";