1--TEST-- 2Test strspn() function : usage variations - unexpected values of start argument 3--FILE-- 4<?php 5/* Prototype : proto int strspn(string str, string mask [, int start [, int len]]) 6 * Description: Finds length of initial segment consisting entirely of characters found in mask. 7 If start or/and length is provided works like strspn(substr($s,$start,$len),$good_chars) 8 * Source code: ext/standard/string.c 9 * Alias to functions: none 10*/ 11 12error_reporting(E_ALL & ~E_NOTICE); 13 14/* 15* Testing strspn() : with unexpected values of start argument 16*/ 17 18echo "*** Testing strspn() : with unexpected values of start argument ***\n"; 19 20// initialing required variables 21$str = 'string_val'; 22$mask = 'soibtFTf1234567890'; 23$len = 10; 24 25//get an unset variable 26$unset_var = 10; 27unset ($unset_var); 28 29// declaring class 30class sample { 31 public function __toString() { 32 return "object"; 33 } 34} 35 36// creating a file resource 37$file_handle = fopen(__FILE__, 'r'); 38 39 40//array of values to iterate over 41$values = array( 42 43 // float data 44 10.5, 45 -10.5, 46 10.1234567e8, 47 10.7654321E-8, 48 .5, 49 50 // array data 51 array(), 52 array(0), 53 array(1), 54 array(1, 2), 55 array('color' => 'red', 'item' => 'pen'), 56 57 // null data 58 NULL, 59 null, 60 61 // boolean data 62 true, 63 false, 64 TRUE, 65 FALSE, 66 67 // empty data 68 "", 69 '', 70 71 // string data 72 "string", 73 'string', 74 75 // object data 76 new sample(), 77 78 // undefined data 79 $undefined_var, 80 81 // unset data 82 $unset_var, 83 84 // resource 85 $file_handle 86); 87 88// loop through each element of the array for start 89 90foreach($values as $value) { 91 echo "\n-- Iteration with start value as \"$value\" --\n"; 92 var_dump( strspn($str,$mask,$value) ); // with default len value 93 var_dump( strspn($str,$mask,$value,$len) ); // with all args 94}; 95 96// closing the resource 97fclose($file_handle); 98 99echo "Done" 100?> 101--EXPECTF-- 102*** Testing strspn() : with unexpected values of start argument *** 103 104-- Iteration with start value as "10.5" -- 105int(0) 106int(0) 107 108-- Iteration with start value as "-10.5" -- 109int(2) 110int(2) 111 112-- Iteration with start value as "1012345670" -- 113bool(false) 114bool(false) 115 116-- Iteration with start value as "1.07654321E-7" -- 117int(2) 118int(2) 119 120-- Iteration with start value as "0.5" -- 121int(2) 122int(2) 123 124-- Iteration with start value as "Array" -- 125 126Warning: strspn() expects parameter 3 to be integer, array given in %s on line %d 127NULL 128 129Warning: strspn() expects parameter 3 to be integer, array given in %s on line %d 130NULL 131 132-- Iteration with start value as "Array" -- 133 134Warning: strspn() expects parameter 3 to be integer, array given in %s on line %d 135NULL 136 137Warning: strspn() expects parameter 3 to be integer, array given in %s on line %d 138NULL 139 140-- Iteration with start value as "Array" -- 141 142Warning: strspn() expects parameter 3 to be integer, array given in %s on line %d 143NULL 144 145Warning: strspn() expects parameter 3 to be integer, array given in %s on line %d 146NULL 147 148-- Iteration with start value as "Array" -- 149 150Warning: strspn() expects parameter 3 to be integer, array given in %s on line %d 151NULL 152 153Warning: strspn() expects parameter 3 to be integer, array given in %s on line %d 154NULL 155 156-- Iteration with start value as "Array" -- 157 158Warning: strspn() expects parameter 3 to be integer, array given in %s on line %d 159NULL 160 161Warning: strspn() expects parameter 3 to be integer, array given in %s on line %d 162NULL 163 164-- Iteration with start value as "" -- 165int(2) 166int(2) 167 168-- Iteration with start value as "" -- 169int(2) 170int(2) 171 172-- Iteration with start value as "1" -- 173int(1) 174int(1) 175 176-- Iteration with start value as "" -- 177int(2) 178int(2) 179 180-- Iteration with start value as "1" -- 181int(1) 182int(1) 183 184-- Iteration with start value as "" -- 185int(2) 186int(2) 187 188-- Iteration with start value as "" -- 189 190Warning: strspn() expects parameter 3 to be integer, string given in %s on line %d 191NULL 192 193Warning: strspn() expects parameter 3 to be integer, string given in %s on line %d 194NULL 195 196-- Iteration with start value as "" -- 197 198Warning: strspn() expects parameter 3 to be integer, string given in %s on line %d 199NULL 200 201Warning: strspn() expects parameter 3 to be integer, string given in %s on line %d 202NULL 203 204-- Iteration with start value as "string" -- 205 206Warning: strspn() expects parameter 3 to be integer, string given in %s on line %d 207NULL 208 209Warning: strspn() expects parameter 3 to be integer, string given in %s on line %d 210NULL 211 212-- Iteration with start value as "string" -- 213 214Warning: strspn() expects parameter 3 to be integer, string given in %s on line %d 215NULL 216 217Warning: strspn() expects parameter 3 to be integer, string given in %s on line %d 218NULL 219 220-- Iteration with start value as "object" -- 221 222Warning: strspn() expects parameter 3 to be integer, object given in %s on line %d 223NULL 224 225Warning: strspn() expects parameter 3 to be integer, object given in %s on line %d 226NULL 227 228-- Iteration with start value as "" -- 229int(2) 230int(2) 231 232-- Iteration with start value as "" -- 233int(2) 234int(2) 235 236-- Iteration with start value as "Resource id #%d" -- 237 238Warning: strspn() expects parameter 3 to be integer, resource given in %s on line %d 239NULL 240 241Warning: strspn() expects parameter 3 to be integer, resource given in %s on line %d 242NULL 243Done