php-src/ext/standard/tests/array/array_search_errors.phpt

45 lines
1.2 KiB
Plaintext
Raw Normal View History

2007-06-28 15:27:09 +00:00
--TEST--
Test array_search() function - error conditions
2007-06-28 15:27:09 +00:00
--FILE--
<?php
/*
* Prototype : mixed array_search ( mixed $needle, array $haystack [, bool $strict] )
* Description: Searches haystack for needle and returns the key if it is found in the array, FALSE otherwise
* Source Code: ext/standard/array.c
*/
2007-06-28 15:27:09 +00:00
echo "*** Testing error conditions of array_search() ***\n";
2007-06-28 15:27:09 +00:00
/* zero argument */
var_dump( array_search() );
2007-06-28 15:27:09 +00:00
/* unexpected no.of arguments in array_search() */
2007-06-28 15:27:09 +00:00
$var = array("mon", "tues", "wed", "thurs");
var_dump( array_search(1, $var, 0, "test") );
var_dump( array_search("test") );
2007-06-28 15:27:09 +00:00
/* unexpected second argument in array_search() */
2007-06-28 15:27:09 +00:00
$var="test";
var_dump( array_search("test", $var) );
var_dump( array_search(1, 123) );
2007-06-28 15:27:09 +00:00
echo "Done\n";
?>
--EXPECTF--
*** Testing error conditions of array_search() ***
2007-06-28 15:27:09 +00:00
Warning: array_search() expects at least 2 parameters, 0 given in %s on line %d
2007-06-28 15:27:09 +00:00
NULL
Warning: array_search() expects at most 3 parameters, 4 given in %s on line %d
2007-06-28 15:27:09 +00:00
NULL
Warning: array_search() expects at least 2 parameters, 1 given in %s on line %d
2007-06-28 15:27:09 +00:00
NULL
Warning: array_search() expects parameter 2 to be array, string given in %s on line %d
NULL
2007-06-28 15:27:09 +00:00
Warning: array_search() expects parameter 2 to be array, integer given in %s on line %d
NULL
2007-06-28 15:27:09 +00:00
Done