Return to strspn_variation1.phpt CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / ext / standard / tests / strings |
1.1 misho 1: --TEST-- 2: Test strspn() function : usage variations - unexpected values for str 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: 12: error_reporting(E_ALL & ~E_NOTICE); 13: 14: /* 15: * Testing strspn() : with different unexpected values for str argument 16: */ 17: 18: echo "*** Testing strspn() : with unexpected values for str argument ***\n"; 19: 20: // Initialise function arguments not being substititued (if any) 21: $mask = 'abons1234567890'; 22: $start = 1; 23: $len = 10; 24: 25: 26: //get an unset variable 27: $unset_var = 10; 28: unset ($unset_var); 29: 30: // declaring class 31: class sample { 32: public function __toString() { 33: return "object"; 34: } 35: } 36: 37: // creating a file resource 38: $file_handle = fopen(__FILE__, 'r'); 39: 40: 41: //array of values to iterate over 42: $values = array( 43: 44: // int data 45: 0, 46: 1, 47: 12345, 48: -2345, 49: 50: // float data 51: 10.5, 52: -10.5, 53: 10.1234567e10, 54: 10.7654321E-10, 55: .5, 56: 57: // array data 58: array(), 59: array(0), 60: array(1), 61: array(1, 2), 62: array('color' => 'red', 'item' => 'pen'), 63: 64: // null data 65: NULL, 66: null, 67: 68: // boolean data 69: true, 70: false, 71: TRUE, 72: FALSE, 73: 74: // empty data 75: "", 76: '', 77: 78: // object data 79: new sample, 80: 81: // undefined data 82: $undefined_var, 83: 84: // unset data 85: $unset_var, 86: 87: // resource 88: $file_handle 89: ); 90: 91: // loop through each element of the array for str 92: 93: foreach($values as $value) { 94: echo "\n-- Iteration with str value as \"$value\"\n"; 95: var_dump( strspn($value,$mask) ); // with default args 96: var_dump( strspn($value,$mask,$start) ); // with default len value 97: var_dump( strspn($value,$mask,$start,$len) ); // with all args 98: }; 99: 100: // closing the resource 101: fclose($file_handle); 102: 103: echo "Done" 104: ?> 105: --EXPECTF-- 106: *** Testing strspn() : with unexpected values for str argument *** 107: 108: -- Iteration with str value as "0" 109: int(1) 110: int(0) 111: int(0) 112: 113: -- Iteration with str value as "1" 114: int(1) 115: int(0) 116: int(0) 117: 118: -- Iteration with str value as "12345" 119: int(5) 120: int(4) 121: int(4) 122: 123: -- Iteration with str value as "-2345" 124: int(0) 125: int(4) 126: int(4) 127: 128: -- Iteration with str value as "10.5" 129: int(2) 130: int(1) 131: int(1) 132: 133: -- Iteration with str value as "-10.5" 134: int(0) 135: int(2) 136: int(2) 137: 138: -- Iteration with str value as "101234567000" 139: int(12) 140: int(11) 141: int(10) 142: 143: -- Iteration with str value as "1.07654321E-9" 144: int(1) 145: int(0) 146: int(0) 147: 148: -- Iteration with str value as "0.5" 149: int(1) 150: int(0) 151: int(0) 152: 153: -- Iteration with str value as "Array" 154: 155: Warning: strspn() expects parameter 1 to be string, array given in %s on line %d 156: NULL 157: 158: Warning: strspn() expects parameter 1 to be string, array given in %s on line %d 159: NULL 160: 161: Warning: strspn() expects parameter 1 to be string, array given in %s on line %d 162: NULL 163: 164: -- Iteration with str value as "Array" 165: 166: Warning: strspn() expects parameter 1 to be string, array given in %s on line %d 167: NULL 168: 169: Warning: strspn() expects parameter 1 to be string, array given in %s on line %d 170: NULL 171: 172: Warning: strspn() expects parameter 1 to be string, array given in %s on line %d 173: NULL 174: 175: -- Iteration with str value as "Array" 176: 177: Warning: strspn() expects parameter 1 to be string, array given in %s on line %d 178: NULL 179: 180: Warning: strspn() expects parameter 1 to be string, array given in %s on line %d 181: NULL 182: 183: Warning: strspn() expects parameter 1 to be string, array given in %s on line %d 184: NULL 185: 186: -- Iteration with str value as "Array" 187: 188: Warning: strspn() expects parameter 1 to be string, array given in %s on line %d 189: NULL 190: 191: Warning: strspn() expects parameter 1 to be string, array given in %s on line %d 192: NULL 193: 194: Warning: strspn() expects parameter 1 to be string, array given in %s on line %d 195: NULL 196: 197: -- Iteration with str value as "Array" 198: 199: Warning: strspn() expects parameter 1 to be string, array given in %s on line %d 200: NULL 201: 202: Warning: strspn() expects parameter 1 to be string, array given in %s on line %d 203: NULL 204: 205: Warning: strspn() expects parameter 1 to be string, array given in %s on line %d 206: NULL 207: 208: -- Iteration with str value as "" 209: int(0) 210: bool(false) 211: bool(false) 212: 213: -- Iteration with str value as "" 214: int(0) 215: bool(false) 216: bool(false) 217: 218: -- Iteration with str value as "1" 219: int(1) 220: int(0) 221: int(0) 222: 223: -- Iteration with str value as "" 224: int(0) 225: bool(false) 226: bool(false) 227: 228: -- Iteration with str value as "1" 229: int(1) 230: int(0) 231: int(0) 232: 233: -- Iteration with str value as "" 234: int(0) 235: bool(false) 236: bool(false) 237: 238: -- Iteration with str value as "" 239: int(0) 240: bool(false) 241: bool(false) 242: 243: -- Iteration with str value as "" 244: int(0) 245: bool(false) 246: bool(false) 247: 248: -- Iteration with str value as "object" 249: int(2) 250: int(1) 251: int(1) 252: 253: -- Iteration with str value as "" 254: int(0) 255: bool(false) 256: bool(false) 257: 258: -- Iteration with str value as "" 259: int(0) 260: bool(false) 261: bool(false) 262: 263: -- Iteration with str value as "Resource id #%d" 264: 265: Warning: strspn() expects parameter 1 to be string, resource given in %s on line %d 266: NULL 267: 268: Warning: strspn() expects parameter 1 to be string, resource given in %s on line %d 269: NULL 270: 271: Warning: strspn() expects parameter 1 to be string, resource given in %s on line %d 272: NULL 273: Done