1--TEST-- 2Test strspn() function : usage variations - unexpected values of len 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 len argument 16*/ 17 18echo "*** Testing strspn() : with unexpected values of len argument ***\n"; 19 20// initialing required variables 21$str = 'string_val'; 22$mask = 'soibtFTf1234567890'; 23$start = 0; 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 len value as \"$value\" --\n"; 92 var_dump( strspn($str,$mask,$start,$value) ); // with all args 93}; 94 95// closing the resource 96fclose($file_handle); 97 98echo "Done" 99?> 100--EXPECTF-- 101*** Testing strspn() : with unexpected values of len argument *** 102 103-- Iteration with len value as "10.5" -- 104int(2) 105 106-- Iteration with len value as "-10.5" -- 107int(0) 108 109-- Iteration with len value as "1012345670" -- 110int(2) 111 112-- Iteration with len value as "1.07654321E-7" -- 113int(0) 114 115-- Iteration with len value as "0.5" -- 116int(0) 117 118-- Iteration with len value as "Array" -- 119 120Warning: strspn() expects parameter 4 to be integer, array given in %s on line %d 121NULL 122 123-- Iteration with len value as "Array" -- 124 125Warning: strspn() expects parameter 4 to be integer, array given in %s on line %d 126NULL 127 128-- Iteration with len value as "Array" -- 129 130Warning: strspn() expects parameter 4 to be integer, array given in %s on line %d 131NULL 132 133-- Iteration with len value as "Array" -- 134 135Warning: strspn() expects parameter 4 to be integer, array given in %s on line %d 136NULL 137 138-- Iteration with len value as "Array" -- 139 140Warning: strspn() expects parameter 4 to be integer, array given in %s on line %d 141NULL 142 143-- Iteration with len value as "" -- 144int(0) 145 146-- Iteration with len value as "" -- 147int(0) 148 149-- Iteration with len value as "1" -- 150int(1) 151 152-- Iteration with len value as "" -- 153int(0) 154 155-- Iteration with len value as "1" -- 156int(1) 157 158-- Iteration with len value as "" -- 159int(0) 160 161-- Iteration with len value as "" -- 162 163Warning: strspn() expects parameter 4 to be integer, string given in %s on line %d 164NULL 165 166-- Iteration with len value as "" -- 167 168Warning: strspn() expects parameter 4 to be integer, string given in %s on line %d 169NULL 170 171-- Iteration with len value as "string" -- 172 173Warning: strspn() expects parameter 4 to be integer, string given in %s on line %d 174NULL 175 176-- Iteration with len value as "string" -- 177 178Warning: strspn() expects parameter 4 to be integer, string given in %s on line %d 179NULL 180 181-- Iteration with len value as "object" -- 182 183Warning: strspn() expects parameter 4 to be integer, object given in %s on line %d 184NULL 185 186-- Iteration with len value as "" -- 187int(0) 188 189-- Iteration with len value as "" -- 190int(0) 191 192-- Iteration with len value as "Resource id #%d" -- 193 194Warning: strspn() expects parameter 4 to be integer, resource given in %s on line %d 195NULL 196Done 197