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