1--TEST-- 2Test strcspn() function : usage variations - unexpected values of len argument 3--FILE-- 4<?php 5/* Prototype : proto int strcspn(string str, string mask [, int start [, int len]]) 6 * Description: Finds length of initial segment consisting entirely of characters not found in mask. 7 If start or/and length is provided works like strcspn(substr($s,$start,$len),$bad_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 strcspn() : with unexpected values of len argument 16*/ 17 18echo "*** Testing strcspn() : 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.1234567e10, 47 10.7654321E-10, 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( strcspn($str,$mask,$start,$value) ); // with all args 93}; 94 95// closing the resource 96fclose($file_handle); 97 98echo "Done" 99?> 100--EXPECTF-- 101*** Testing strcspn() : with unexpected values of len argument *** 102 103-- Iteration with len value as "10.5" -- 104int(0) 105 106-- Iteration with len value as "-10.5" -- 107int(0) 108 109-- Iteration with len value as "101234567000" -- 110int(0) 111 112-- Iteration with len value as "1.07654321E-9" -- 113int(0) 114 115-- Iteration with len value as "0.5" -- 116int(0) 117 118-- Iteration with len value as "Array" -- 119 120Warning: strcspn() expects parameter 4 to be long, array given in %s on line %d 121NULL 122 123-- Iteration with len value as "Array" -- 124 125Warning: strcspn() expects parameter 4 to be long, array given in %s on line %d 126NULL 127 128-- Iteration with len value as "Array" -- 129 130Warning: strcspn() expects parameter 4 to be long, array given in %s on line %d 131NULL 132 133-- Iteration with len value as "Array" -- 134 135Warning: strcspn() expects parameter 4 to be long, array given in %s on line %d 136NULL 137 138-- Iteration with len value as "Array" -- 139 140Warning: strcspn() expects parameter 4 to be long, 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(0) 151 152-- Iteration with len value as "" -- 153int(0) 154 155-- Iteration with len value as "1" -- 156int(0) 157 158-- Iteration with len value as "" -- 159int(0) 160 161-- Iteration with len value as "" -- 162 163Warning: strcspn() expects parameter 4 to be long, string given in %s on line %d 164NULL 165 166-- Iteration with len value as "" -- 167 168Warning: strcspn() expects parameter 4 to be long, string given in %s on line %d 169NULL 170 171-- Iteration with len value as "string" -- 172 173Warning: strcspn() expects parameter 4 to be long, string given in %s on line %d 174NULL 175 176-- Iteration with len value as "string" -- 177 178Warning: strcspn() expects parameter 4 to be long, string given in %s on line %d 179NULL 180 181-- Iteration with len value as "object" -- 182 183Warning: strcspn() expects parameter 4 to be long, 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: strcspn() expects parameter 4 to be long, resource given in %s on line %d 195NULL 196Done