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