1--TEST-- 2Test stripos() function : usage variations - unexpected inputs for 'haystack' and 'needle' arguments 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' and 'needle' arguments */ 11 12echo "*** Testing stripos() function with unexpected values for haystack and needle ***\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$values = 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 79// loop through each element of the array and check the working of stripos() 80$counter = 1; 81for($index = 0; $index < count($values); $index ++) { 82 echo "-- Iteration $counter --\n"; 83 $haystack = $values[$index]; 84 var_dump( stripos($values[$index], $values[$index]) ); 85 var_dump( stripos($values[$index], $values[$index], 1) ); 86 $counter ++; 87} 88 89echo "*** Done ***"; 90?> 91--EXPECTF-- 92*** Testing stripos() function with unexpected values for haystack and needle *** 93-- Iteration 1 -- 94 95Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d 96bool(false) 97 98Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d 99bool(false) 100-- Iteration 2 -- 101 102Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d 103bool(false) 104 105Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d 106bool(false) 107-- Iteration 3 -- 108 109Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d 110bool(false) 111 112Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d 113bool(false) 114-- Iteration 4 -- 115 116Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d 117bool(false) 118 119Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d 120bool(false) 121-- Iteration 5 -- 122 123Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d 124bool(false) 125 126Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d 127bool(false) 128-- Iteration 6 -- 129 130Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d 131bool(false) 132 133Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d 134bool(false) 135-- Iteration 7 -- 136 137Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d 138bool(false) 139 140Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d 141bool(false) 142-- Iteration 8 -- 143 144Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d 145bool(false) 146 147Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d 148bool(false) 149-- Iteration 9 -- 150 151Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d 152bool(false) 153 154Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d 155bool(false) 156-- Iteration 10 -- 157 158Warning: stripos() expects parameter 1 to be string, array given in %s on line %d 159NULL 160 161Warning: stripos() expects parameter 1 to be string, array given in %s on line %d 162NULL 163-- Iteration 11 -- 164 165Warning: stripos() expects parameter 1 to be string, array given in %s on line %d 166NULL 167 168Warning: stripos() expects parameter 1 to be string, array given in %s on line %d 169NULL 170-- Iteration 12 -- 171 172Warning: stripos() expects parameter 1 to be string, array given in %s on line %d 173NULL 174 175Warning: stripos() expects parameter 1 to be string, array given in %s on line %d 176NULL 177-- Iteration 13 -- 178 179Warning: stripos() expects parameter 1 to be string, array given in %s on line %d 180NULL 181 182Warning: stripos() expects parameter 1 to be string, array given in %s on line %d 183NULL 184-- Iteration 14 -- 185 186Warning: stripos() expects parameter 1 to be string, array given in %s on line %d 187NULL 188 189Warning: stripos() expects parameter 1 to be string, array given in %s on line %d 190NULL 191-- Iteration 15 -- 192 193Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d 194bool(false) 195 196Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d 197bool(false) 198-- Iteration 16 -- 199bool(false) 200 201Warning: stripos(): Offset not contained in string in %s on line %d 202bool(false) 203-- Iteration 17 -- 204 205Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d 206bool(false) 207 208Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d 209bool(false) 210-- Iteration 18 -- 211bool(false) 212 213Warning: stripos(): Offset not contained in string in %s on line %d 214bool(false) 215-- Iteration 19 -- 216 217Notice: Object of class sample could not be converted to int in %s on line %d 218 219Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d 220bool(false) 221 222Notice: Object of class sample could not be converted to int in %s on line %d 223 224Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d 225bool(false) 226-- Iteration 20 -- 227bool(false) 228 229Warning: stripos(): Offset not contained in string in %s on line %d 230bool(false) 231-- Iteration 21 -- 232bool(false) 233 234Warning: stripos(): Offset not contained in string in %s on line %d 235bool(false) 236-- Iteration 22 -- 237bool(false) 238 239Warning: stripos(): Offset not contained in string in %s on line %d 240bool(false) 241-- Iteration 23 -- 242bool(false) 243 244Warning: stripos(): Offset not contained in string in %s on line %d 245bool(false) 246-- Iteration 24 -- 247 248Warning: stripos() expects parameter 1 to be string, resource given in %s on line %d 249NULL 250 251Warning: stripos() expects parameter 1 to be string, resource given in %s on line %d 252NULL 253-- Iteration 25 -- 254bool(false) 255 256Warning: stripos(): Offset not contained in string in %s on line %d 257bool(false) 258-- Iteration 26 -- 259bool(false) 260 261Warning: stripos(): Offset not contained in string in %s on line %d 262bool(false) 263*** Done *** 264