1--TEST-- 2Test stripos() function : usage variations - unexpected inputs for 'haystack' argument 3--FILE-- 4<?php 5/* Prototype : int stripos ( string $haystack, string $needle [, int $offset] ); 6 * Description: Find position of first occurrence of a case-insensitive string 7 * Source code: ext/standard/string.c 8*/ 9 10/* Test stripos() function with unexpected inputs for haystack argument */ 11 12echo "*** Testing stripos() function with unexpected values for haystack ***\n"; 13 14// get an unset variable 15$unset_var = 'string_val'; 16unset($unset_var); 17 18// defining a class 19class sample { 20 public function __toString() { 21 return "object"; 22 } 23} 24 25//getting the resource 26$file_handle = fopen(__FILE__, "r"); 27 28// array with different values 29$haystacks = array ( 30 31 // integer values 32 0, 33 1, 34 12345, 35 -2345, 36 37 // float values 38 10.5, 39 -10.5, 40 10.5e10, 41 10.6E-10, 42 .5, 43 44 // array values 45 array(), 46 array(0), 47 array(1), 48 array(1, 2), 49 array('color' => 'red', 'item' => 'pen'), 50 51 // boolean values 52 true, 53 false, 54 TRUE, 55 FALSE, 56 57 // objects 58 new sample(), 59 60 // empty string 61 "", 62 '', 63 64 // null values 65 NULL, 66 null, 67 68 // resource 69 $file_handle, 70 71 // undefined variable 72 @$undefined_var, 73 74 // unset variable 75 @$unset_var 76); 77 78$needle = "heredoc 0 1 2 -2 10.5 -10.5 10.5e10 10.6E-10 .5 array true false object \"\" null Resource"; 79 80// loop through each element of the array and check the working of stripos() 81$counter = 1; 82for($index = 0; $index < count($haystacks); $index ++) { 83 echo "\n-- Iteration $counter --\n"; 84 var_dump( stripos($haystacks[$index], $needle) ); 85 $counter ++; 86} 87 88fclose($file_handle); //closing the file handle 89 90echo "*** Done ***"; 91?> 92--EXPECTF-- 93*** Testing stripos() function with unexpected values for haystack *** 94 95-- Iteration 1 -- 96bool(false) 97 98-- Iteration 2 -- 99bool(false) 100 101-- Iteration 3 -- 102bool(false) 103 104-- Iteration 4 -- 105bool(false) 106 107-- Iteration 5 -- 108bool(false) 109 110-- Iteration 6 -- 111bool(false) 112 113-- Iteration 7 -- 114bool(false) 115 116-- Iteration 8 -- 117bool(false) 118 119-- Iteration 9 -- 120bool(false) 121 122-- Iteration 10 -- 123 124Warning: stripos() expects parameter 1 to be string, array given in %s on line %d 125NULL 126 127-- Iteration 11 -- 128 129Warning: stripos() expects parameter 1 to be string, array given in %s on line %d 130NULL 131 132-- Iteration 12 -- 133 134Warning: stripos() expects parameter 1 to be string, array given in %s on line %d 135NULL 136 137-- Iteration 13 -- 138 139Warning: stripos() expects parameter 1 to be string, array given in %s on line %d 140NULL 141 142-- Iteration 14 -- 143 144Warning: stripos() expects parameter 1 to be string, array given in %s on line %d 145NULL 146 147-- Iteration 15 -- 148bool(false) 149 150-- Iteration 16 -- 151bool(false) 152 153-- Iteration 17 -- 154bool(false) 155 156-- Iteration 18 -- 157bool(false) 158 159-- Iteration 19 -- 160bool(false) 161 162-- Iteration 20 -- 163bool(false) 164 165-- Iteration 21 -- 166bool(false) 167 168-- Iteration 22 -- 169bool(false) 170 171-- Iteration 23 -- 172bool(false) 173 174-- Iteration 24 -- 175 176Warning: stripos() expects parameter 1 to be string, resource given in %s on line %d 177NULL 178 179-- Iteration 25 -- 180bool(false) 181 182-- Iteration 26 -- 183bool(false) 184*** Done *** 185