1--TEST-- 2Test strrchr() function : usage variations - unexpected inputs for haystack and needle 3--FILE-- 4<?php 5/* Prototype : string strrchr(string $haystack, string $needle); 6 * Description: Finds the last occurrence of a character in a string. 7 * Source code: ext/standard/string.c 8*/ 9 10/* Test strrchr() function with unexpected inputs for haystack and needle */ 11 12echo "*** Testing strrchr() function: with unexpected inputs for haystack and needle ***\n"; 13 14// get an unset variable 15$unset_var = 'string_val'; 16unset($unset_var); 17 18// declaring 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.1234567e10, 41 10.7654321E-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 strrchr() 80$counter = 1; 81for($index = 0; $index < count($values); $index ++) { 82 echo "-- Iteration $counter --\n"; 83 var_dump( strrchr($values[$index], $values[$index]) ); 84 $counter ++; 85} 86 87fclose($file_handle); //closing the file handle 88 89echo "*** Done ***"; 90?> 91--EXPECTF-- 92*** Testing strrchr() function: with unexpected inputs for haystack and needle *** 93-- Iteration 1 -- 94 95Deprecated: strrchr(): Non-string needles will be interpreted as strings in %s on line %d 96bool(false) 97-- Iteration 2 -- 98 99Deprecated: strrchr(): Non-string needles will be interpreted as strings in %s on line %d 100bool(false) 101-- Iteration 3 -- 102 103Deprecated: strrchr(): Non-string needles will be interpreted as strings in %s on line %d 104bool(false) 105-- Iteration 4 -- 106 107Deprecated: strrchr(): Non-string needles will be interpreted as strings in %s on line %d 108bool(false) 109-- Iteration 5 -- 110 111Deprecated: strrchr(): Non-string needles will be interpreted as strings in %s on line %d 112bool(false) 113-- Iteration 6 -- 114 115Deprecated: strrchr(): Non-string needles will be interpreted as strings in %s on line %d 116bool(false) 117-- Iteration 7 -- 118 119Deprecated: strrchr(): Non-string needles will be interpreted as strings in %s on line %d 120bool(false) 121-- Iteration 8 -- 122 123Deprecated: strrchr(): Non-string needles will be interpreted as strings in %s on line %d 124bool(false) 125-- Iteration 9 -- 126 127Deprecated: strrchr(): Non-string needles will be interpreted as strings in %s on line %d 128bool(false) 129-- Iteration 10 -- 130 131Warning: strrchr() expects parameter 1 to be string, array given in %s on line %d 132NULL 133-- Iteration 11 -- 134 135Warning: strrchr() expects parameter 1 to be string, array given in %s on line %d 136NULL 137-- Iteration 12 -- 138 139Warning: strrchr() expects parameter 1 to be string, array given in %s on line %d 140NULL 141-- Iteration 13 -- 142 143Warning: strrchr() expects parameter 1 to be string, array given in %s on line %d 144NULL 145-- Iteration 14 -- 146 147Warning: strrchr() expects parameter 1 to be string, array given in %s on line %d 148NULL 149-- Iteration 15 -- 150 151Deprecated: strrchr(): Non-string needles will be interpreted as strings in %s on line %d 152bool(false) 153-- Iteration 16 -- 154 155Deprecated: strrchr(): Non-string needles will be interpreted as strings in %s on line %d 156bool(false) 157-- Iteration 17 -- 158 159Deprecated: strrchr(): Non-string needles will be interpreted as strings in %s on line %d 160bool(false) 161-- Iteration 18 -- 162 163Deprecated: strrchr(): Non-string needles will be interpreted as strings in %s on line %d 164bool(false) 165-- Iteration 19 -- 166 167Notice: Object of class sample could not be converted to int in %s on line %d 168 169Deprecated: strrchr(): Non-string needles will be interpreted as strings in %s on line %d 170bool(false) 171-- Iteration 20 -- 172bool(false) 173-- Iteration 21 -- 174bool(false) 175-- Iteration 22 -- 176 177Deprecated: strrchr(): Non-string needles will be interpreted as strings in %s on line %d 178bool(false) 179-- Iteration 23 -- 180 181Deprecated: strrchr(): Non-string needles will be interpreted as strings in %s on line %d 182bool(false) 183-- Iteration 24 -- 184 185Warning: strrchr() expects parameter 1 to be string, resource given in %s on line %d 186NULL 187-- Iteration 25 -- 188 189Deprecated: strrchr(): Non-string needles will be interpreted as strings in %s on line %d 190bool(false) 191-- Iteration 26 -- 192 193Deprecated: strrchr(): Non-string needles will be interpreted as strings in %s on line %d 194bool(false) 195*** Done *** 196