Annotation of embedaddon/php/ext/standard/tests/array/array_search_variation3.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: Test array_search() function : usage variations - haystack as sub-array/object
                      3: --FILE--
                      4: <?php
                      5: /*
                      6:  * Prototype  : mixed array_search ( mixed $needle, array $haystack [, bool $strict] )
                      7:  * Description: Searches haystack for needle and returns the key if it is found in the array, FALSE otherwise
                      8:  * Source Code: ext/standard/array.c
                      9: */
                     10: 
                     11: /* checking for sub-arrays with array_search() */
                     12: echo "*** Testing sub-arrays with array_search() ***\n";
                     13: $sub_array = array (
                     14:   "one", 
                     15:   array(1, 2 => "two", "three" => 3),
                     16:   4 => "four",
                     17:   "five" => 5,
                     18:   array('', 'i')
                     19: );
                     20: var_dump( array_search("four", $sub_array) );
                     21: //checking for element in a sub-array
                     22: var_dump( array_search(3, $sub_array[1]) ); 
                     23: var_dump( array_search(array('','i'), $sub_array) );
                     24: 
                     25: /* checking for objects in array_search() */
                     26: echo "\n*** Testing objects with array_search() ***\n";
                     27: class array_search_check {
                     28:   public $array_var = array(1=>"one", "two"=>2, 3=>3);
                     29:   public function foo() {
                     30:     echo "Public function\n";
                     31:   }
                     32: }
                     33: 
                     34: $array_search_obj = new array_search_check();  //creating new object
                     35: //error: as wrong datatype for second argument
                     36: var_dump( array_search("array_var", $array_search_obj) ); 
                     37: //error: as wrong datatype for second argument
                     38: var_dump( array_search("foo", $array_search_obj) ); 
                     39: //element found as "one" exists in array $array_var
                     40: var_dump( array_search("one", $array_search_obj->array_var) ); 
                     41: 
                     42: echo "Done\n";
                     43: ?>
                     44: --EXPECTF--
                     45: *** Testing sub-arrays with array_search() ***
                     46: int(4)
                     47: string(5) "three"
                     48: int(5)
                     49: 
                     50: *** Testing objects with array_search() ***
                     51: 
                     52: Warning: array_search() expects parameter 2 to be array, object given in %s on line %d
                     53: NULL
                     54: 
                     55: Warning: array_search() expects parameter 2 to be array, object given in %s on line %d
                     56: NULL
                     57: int(1)
                     58: Done

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>