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