Return to chunk_split_variation3.phpt CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / ext / standard / tests / strings |
1.1 misho 1: --TEST-- 2: Test chunk_split() function : usage variations - unexpected values for 'ending' argument 3: --FILE-- 4: <?php 5: /* Prototype : string chunk_split(string $str [, int $chunklen [, string $ending]]) 6: * Description: Returns split line 7: * Source code: ext/standard/string.c 8: * Alias to functions: none 9: */ 10: 11: echo "*** Testing chunk_split() : unexpected values for 'ending' ***\n"; 12: 13: // Initializing variables 14: $str = 'This is simple string.'; 15: $chunklen = 4.9; 16: 17: //get an unset variable 18: $unset_var = 10; 19: unset ($unset_var); 20: 21: //resource variable 22: $fp = fopen(__FILE__,'r'); 23: 24: //Class to get object variable 25: class MyClass 26: { 27: public function __toString() 28: { 29: return "object"; 30: } 31: } 32: 33: //different values for 'ending' 34: $values = array( 35: 36: // int data 37: 0, 38: 1, 39: 12345, 40: -2345, 41: 42: // float data 43: 10.5, 44: -10.5, 45: 10.123456e10, 46: 10.7654321E-10, 47: .5, 48: 49: // array data 50: array(), 51: array(0), 52: array(1), 53: array(1, 2), 54: array('color' => 'red', 'item' => 'pen'), 55: 56: // null data 57: NULL, 58: null, 59: 60: // boolean data 61: true, 62: false, 63: TRUE, 64: FALSE, 65: 66: // empty data 67: "", 68: '', 69: 70: // object data 71: new MyClass(), 72: 73: // undefined data 74: @$undefined_var, 75: 76: // unset data 77: @$unset_var, 78: 79: // resource data 80: $fp 81: ); 82: 83: // loop through each element of values for 'ending' 84: for($count = 0; $count < count($values); $count++) { 85: echo "-- Iteration ".($count+1)." --\n"; 86: var_dump( chunk_split($str, $chunklen, $values[$count]) ); 87: } 88: 89: echo "Done"; 90: 91: //closing resource 92: fclose($fp); 93: ?> 94: --EXPECTF-- 95: *** Testing chunk_split() : unexpected values for 'ending' *** 96: -- Iteration 1 -- 97: string(28) "This0 is 0simp0le s0trin0g.0" 98: -- Iteration 2 -- 99: string(28) "This1 is 1simp1le s1trin1g.1" 100: -- Iteration 3 -- 101: string(52) "This12345 is 12345simp12345le s12345trin12345g.12345" 102: -- Iteration 4 -- 103: string(52) "This-2345 is -2345simp-2345le s-2345trin-2345g.-2345" 104: -- Iteration 5 -- 105: string(46) "This10.5 is 10.5simp10.5le s10.5trin10.5g.10.5" 106: -- Iteration 6 -- 107: string(52) "This-10.5 is -10.5simp-10.5le s-10.5trin-10.5g.-10.5" 108: -- Iteration 7 -- 109: string(94) "This101234560000 is 101234560000simp101234560000le s101234560000trin101234560000g.101234560000" 110: -- Iteration 8 -- 111: string(100) "This1.07654321E-9 is 1.07654321E-9simp1.07654321E-9le s1.07654321E-9trin1.07654321E-9g.1.07654321E-9" 112: -- Iteration 9 -- 113: string(40) "This0.5 is 0.5simp0.5le s0.5trin0.5g.0.5" 114: -- Iteration 10 -- 115: 116: Warning: chunk_split() expects parameter 3 to be string, array given in %s on line %d 117: NULL 118: -- Iteration 11 -- 119: 120: Warning: chunk_split() expects parameter 3 to be string, array given in %s on line %d 121: NULL 122: -- Iteration 12 -- 123: 124: Warning: chunk_split() expects parameter 3 to be string, array given in %s on line %d 125: NULL 126: -- Iteration 13 -- 127: 128: Warning: chunk_split() expects parameter 3 to be string, array given in %s on line %d 129: NULL 130: -- Iteration 14 -- 131: 132: Warning: chunk_split() expects parameter 3 to be string, array given in %s on line %d 133: NULL 134: -- Iteration 15 -- 135: string(22) "This is simple string." 136: -- Iteration 16 -- 137: string(22) "This is simple string." 138: -- Iteration 17 -- 139: string(28) "This1 is 1simp1le s1trin1g.1" 140: -- Iteration 18 -- 141: string(22) "This is simple string." 142: -- Iteration 19 -- 143: string(28) "This1 is 1simp1le s1trin1g.1" 144: -- Iteration 20 -- 145: string(22) "This is simple string." 146: -- Iteration 21 -- 147: string(22) "This is simple string." 148: -- Iteration 22 -- 149: string(22) "This is simple string." 150: -- Iteration 23 -- 151: string(58) "Thisobject is objectsimpobjectle sobjecttrinobjectg.object" 152: -- Iteration 24 -- 153: string(22) "This is simple string." 154: -- Iteration 25 -- 155: string(22) "This is simple string." 156: -- Iteration 26 -- 157: 158: Warning: chunk_split() expects parameter 3 to be string, resource given in %s on line %d 159: NULL 160: Done