--TEST-- Test stripos() function : usage variations - unexpected inputs for 'haystack' and 'needle' arguments --FILE-- 'red', 'item' => 'pen'), // boolean values true, false, TRUE, FALSE, // objects new sample(), // empty string "", '', // null values NULL, null, // resource $file_handle, // undefined variable @$undefined_var, // unset variable @$unset_var ); // loop through each element of the array and check the working of stripos() $counter = 1; for($index = 0; $index < count($values); $index ++) { echo "-- Iteration $counter --\n"; $haystack = $values[$index]; try { var_dump( stripos($values[$index], $values[$index]) ); } catch (Error $e) { echo get_class($e) . ": " . $e->getMessage(), "\n"; } try { var_dump( stripos($values[$index], $values[$index], 1) ); } catch (Error $e) { echo get_class($e) . ": " . $e->getMessage(), "\n"; } $counter ++; } echo "*** Done ***"; ?> --EXPECT-- *** Testing stripos() function with unexpected values for haystack and needle *** -- Iteration 1 -- int(0) bool(false) -- Iteration 2 -- int(0) bool(false) -- Iteration 3 -- int(0) bool(false) -- Iteration 4 -- int(0) bool(false) -- Iteration 5 -- int(0) bool(false) -- Iteration 6 -- int(0) bool(false) -- Iteration 7 -- int(0) bool(false) -- Iteration 8 -- int(0) bool(false) -- Iteration 9 -- int(0) bool(false) -- Iteration 10 -- TypeError: stripos(): Argument #1 ($haystack) must be of type string, array given TypeError: stripos(): Argument #1 ($haystack) must be of type string, array given -- Iteration 11 -- TypeError: stripos(): Argument #1 ($haystack) must be of type string, array given TypeError: stripos(): Argument #1 ($haystack) must be of type string, array given -- Iteration 12 -- TypeError: stripos(): Argument #1 ($haystack) must be of type string, array given TypeError: stripos(): Argument #1 ($haystack) must be of type string, array given -- Iteration 13 -- TypeError: stripos(): Argument #1 ($haystack) must be of type string, array given TypeError: stripos(): Argument #1 ($haystack) must be of type string, array given -- Iteration 14 -- TypeError: stripos(): Argument #1 ($haystack) must be of type string, array given TypeError: stripos(): Argument #1 ($haystack) must be of type string, array given -- Iteration 15 -- int(0) bool(false) -- Iteration 16 -- int(0) ValueError: stripos(): Argument #3 ($offset) must be contained in argument #1 ($haystack) -- Iteration 17 -- int(0) bool(false) -- Iteration 18 -- int(0) ValueError: stripos(): Argument #3 ($offset) must be contained in argument #1 ($haystack) -- Iteration 19 -- int(0) bool(false) -- Iteration 20 -- int(0) ValueError: stripos(): Argument #3 ($offset) must be contained in argument #1 ($haystack) -- Iteration 21 -- int(0) ValueError: stripos(): Argument #3 ($offset) must be contained in argument #1 ($haystack) -- Iteration 22 -- int(0) ValueError: stripos(): Argument #3 ($offset) must be contained in argument #1 ($haystack) -- Iteration 23 -- int(0) ValueError: stripos(): Argument #3 ($offset) must be contained in argument #1 ($haystack) -- Iteration 24 -- TypeError: stripos(): Argument #1 ($haystack) must be of type string, resource given TypeError: stripos(): Argument #1 ($haystack) must be of type string, resource given -- Iteration 25 -- int(0) ValueError: stripos(): Argument #3 ($offset) must be contained in argument #1 ($haystack) -- Iteration 26 -- int(0) ValueError: stripos(): Argument #3 ($offset) must be contained in argument #1 ($haystack) *** Done ***