1--TEST-- 2Test stripos() function : usage variations - unexpected inputs for 'offset' 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 'offset' argument */ 11 12echo "*** Testing stripos() function with unexpected values for offset ***\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//definition of input args 29$haystack = "hello world"; 30$needle = "world"; 31 32// array with different values 33$offsets = array ( 34 35 // float values 36 1.5, 37 -1.5, 38 1.5e6, 39 1.6E-10, 40 .5, 41 42 // array values 43 array(), 44 array(0), 45 array(1), 46 array(1, 2), 47 array('color' => 'red', 'item' => 'pen'), 48 49 // boolean values 50 true, 51 false, 52 TRUE, 53 FALSE, 54 55 // objects 56 new sample(), 57 58 // empty string 59 "", 60 '', 61 62 // null vlaues 63 NULL, 64 null, 65 66 //resource 67 $file_handle, 68 69 // undefined variable 70 @$undefined_var, 71 72 // unset variable 73 @$unset_var 74); 75 76 77// loop through each element of the array and check the working of stripos() 78$counter = 1; 79for($index = 0; $index < count($offsets); $index ++) { 80 echo "-- Iteration $counter --\n"; 81 var_dump( stripos($haystack, $needle, $offsets[$index]) ); 82 $counter ++; 83} 84 85echo "*** Done ***"; 86?> 87--EXPECTF-- 88*** Testing stripos() function with unexpected values for offset *** 89-- Iteration 1 -- 90int(6) 91-- Iteration 2 -- 92bool(false) 93-- Iteration 3 -- 94 95Warning: stripos(): Offset not contained in string in %s on line %d 96bool(false) 97-- Iteration 4 -- 98int(6) 99-- Iteration 5 -- 100int(6) 101-- Iteration 6 -- 102 103Warning: stripos() expects parameter 3 to be integer, array given in %s on line %d 104NULL 105-- Iteration 7 -- 106 107Warning: stripos() expects parameter 3 to be integer, array given in %s on line %d 108NULL 109-- Iteration 8 -- 110 111Warning: stripos() expects parameter 3 to be integer, array given in %s on line %d 112NULL 113-- Iteration 9 -- 114 115Warning: stripos() expects parameter 3 to be integer, array given in %s on line %d 116NULL 117-- Iteration 10 -- 118 119Warning: stripos() expects parameter 3 to be integer, array given in %s on line %d 120NULL 121-- Iteration 11 -- 122int(6) 123-- Iteration 12 -- 124int(6) 125-- Iteration 13 -- 126int(6) 127-- Iteration 14 -- 128int(6) 129-- Iteration 15 -- 130 131Warning: stripos() expects parameter 3 to be integer, object given in %s on line %d 132NULL 133-- Iteration 16 -- 134 135Warning: stripos() expects parameter 3 to be integer, string given in %s on line %d 136NULL 137-- Iteration 17 -- 138 139Warning: stripos() expects parameter 3 to be integer, string given in %s on line %d 140NULL 141-- Iteration 18 -- 142int(6) 143-- Iteration 19 -- 144int(6) 145-- Iteration 20 -- 146 147Warning: stripos() expects parameter 3 to be integer, resource given in %s on line %d 148NULL 149-- Iteration 21 -- 150int(6) 151-- Iteration 22 -- 152int(6) 153*** Done *** 154