Return to strcspn_variation3.phpt CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / ext / standard / tests / strings |
1.1 misho 1: --TEST-- 2: Test strcspn() function : usage variations - unexpected values of start 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: 12: error_reporting(E_ALL & ~E_NOTICE); 13: 14: /* 15: * Testing strcspn() : with unexpected values of start argument 16: */ 17: 18: echo "*** Testing strcspn() : 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; 27: unset ($unset_var); 28: 29: // declaring class 30: class 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: 90: foreach($values as $value) { 91: echo "\n-- Iteration with start value as \"$value\" --\n"; 92: var_dump( strcspn($str,$mask,$value) ); // with default len value 93: var_dump( strcspn($str,$mask,$value,$len) ); // with all args 94: }; 95: 96: // closing the resource 97: fclose($file_handle); 98: 99: echo "Done" 100: ?> 101: --EXPECTF-- 102: *** Testing strcspn() : with unexpected values of start argument *** 103: 104: -- Iteration with start value as "10.5" -- 105: int(0) 106: int(0) 107: 108: -- Iteration with start value as "-10.5" -- 109: int(0) 110: int(0) 111: 112: -- Iteration with start value as "1012345670" -- 113: bool(false) 114: bool(false) 115: 116: -- Iteration with start value as "1.07654321E-7" -- 117: int(0) 118: int(0) 119: 120: -- Iteration with start value as "0.5" -- 121: int(0) 122: int(0) 123: 124: -- Iteration with start value as "Array" -- 125: 126: Warning: strcspn() expects parameter 3 to be long, array given in %s on line %d 127: NULL 128: 129: Warning: strcspn() expects parameter 3 to be long, array given in %s on line %d 130: NULL 131: 132: -- Iteration with start value as "Array" -- 133: 134: Warning: strcspn() expects parameter 3 to be long, array given in %s on line %d 135: NULL 136: 137: Warning: strcspn() expects parameter 3 to be long, array given in %s on line %d 138: NULL 139: 140: -- Iteration with start value as "Array" -- 141: 142: Warning: strcspn() expects parameter 3 to be long, array given in %s on line %d 143: NULL 144: 145: Warning: strcspn() expects parameter 3 to be long, array given in %s on line %d 146: NULL 147: 148: -- Iteration with start value as "Array" -- 149: 150: Warning: strcspn() expects parameter 3 to be long, array given in %s on line %d 151: NULL 152: 153: Warning: strcspn() expects parameter 3 to be long, array given in %s on line %d 154: NULL 155: 156: -- Iteration with start value as "Array" -- 157: 158: Warning: strcspn() expects parameter 3 to be long, array given in %s on line %d 159: NULL 160: 161: Warning: strcspn() expects parameter 3 to be long, array given in %s on line %d 162: NULL 163: 164: -- Iteration with start value as "" -- 165: int(0) 166: int(0) 167: 168: -- Iteration with start value as "" -- 169: int(0) 170: int(0) 171: 172: -- Iteration with start value as "1" -- 173: int(0) 174: int(0) 175: 176: -- Iteration with start value as "" -- 177: int(0) 178: int(0) 179: 180: -- Iteration with start value as "1" -- 181: int(0) 182: int(0) 183: 184: -- Iteration with start value as "" -- 185: int(0) 186: int(0) 187: 188: -- Iteration with start value as "" -- 189: 190: Warning: strcspn() expects parameter 3 to be long, string given in %s on line %d 191: NULL 192: 193: Warning: strcspn() expects parameter 3 to be long, string given in %s on line %d 194: NULL 195: 196: -- Iteration with start value as "" -- 197: 198: Warning: strcspn() expects parameter 3 to be long, string given in %s on line %d 199: NULL 200: 201: Warning: strcspn() expects parameter 3 to be long, string given in %s on line %d 202: NULL 203: 204: -- Iteration with start value as "string" -- 205: 206: Warning: strcspn() expects parameter 3 to be long, string given in %s on line %d 207: NULL 208: 209: Warning: strcspn() expects parameter 3 to be long, string given in %s on line %d 210: NULL 211: 212: -- Iteration with start value as "string" -- 213: 214: Warning: strcspn() expects parameter 3 to be long, string given in %s on line %d 215: NULL 216: 217: Warning: strcspn() expects parameter 3 to be long, string given in %s on line %d 218: NULL 219: 220: -- Iteration with start value as "object" -- 221: 222: Warning: strcspn() expects parameter 3 to be long, object given in %s on line %d 223: NULL 224: 225: Warning: strcspn() expects parameter 3 to be long, object given in %s on line %d 226: NULL 227: 228: -- Iteration with start value as "" -- 229: int(0) 230: int(0) 231: 232: -- Iteration with start value as "" -- 233: int(0) 234: int(0) 235: 236: -- Iteration with start value as "Resource id #%d" -- 237: 238: Warning: strcspn() expects parameter 3 to be long, resource given in %s on line %d 239: NULL 240: 241: Warning: strcspn() expects parameter 3 to be long, resource given in %s on line %d 242: NULL 243: Done