1--TEST--
2Test in_array() function : usage variations - haystack as sub-array/object
3--FILE--
4<?php
5/* Test in_array() with haystack as sub-array and object */
6
7/* checking for sub-arrays with in_array() */
8echo "*** Testing sub-arrays with in_array() ***\n";
9$sub_array = array (
10  "one",
11  array(1, 2 => "two", "three" => 3),
12  4 => "four",
13  "five" => 5,
14  array('', 'i')
15);
16var_dump( in_array("four", $sub_array) );
17//checking for element in a sub-array
18var_dump( in_array(3, $sub_array[1]) );
19var_dump( in_array(array('','i'), $sub_array) );
20
21/* checking for objects in in_array() */
22echo "\n*** Testing objects with in_array() ***\n";
23class in_array_check {
24  public $array_var = array(1=>"one", "two"=>2, 3=>3);
25  public function foo() {
26    echo "Public function\n";
27  }
28}
29
30$in_array_obj = new in_array_check();  //creating new object
31//error: as wrong datatype for second argument
32try {
33    var_dump( in_array("array_var", $in_array_obj) );
34} catch (TypeError $e) {
35    echo $e->getMessage(), "\n";
36}
37//error: as wrong datatype for second argument
38try {
39    var_dump( in_array("foo", $in_array_obj) );
40} catch (TypeError $e) {
41    echo $e->getMessage(), "\n";
42}
43//element found as "one" exists in array $array_var
44var_dump( in_array("one", $in_array_obj->array_var) );
45
46echo "Done\n";
47?>
48--EXPECT--
49*** Testing sub-arrays with in_array() ***
50bool(true)
51bool(true)
52bool(true)
53
54*** Testing objects with in_array() ***
55in_array(): Argument #2 ($haystack) must be of type array, in_array_check given
56in_array(): Argument #2 ($haystack) must be of type array, in_array_check given
57bool(true)
58Done
59