Return to chop_variation1.phpt CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / ext / standard / tests / strings |
1.1 misho 1: --TEST-- 2: Test chop() function : usage variations - unexpected values for str argument 3: --FILE-- 4: <?php 5: /* Prototype : string chop ( string $str [, string $charlist] ) 6: * Description: Strip whitespace (or other characters) from the end of a string 7: * Source code: ext/standard/string.c 8: */ 9: 10: /* 11: * Testing chop() : with different unexpected values for $str argument passed to the function 12: */ 13: 14: echo "*** Testing chop() : with unexpected values for str argument ***\n"; 15: // initialize all required variables 16: 17: $charlist = " @#$%1234567890"; 18: // get an unset variable 19: $unset_var = 'string_val'; 20: unset($unset_var); 21: 22: // declaring class 23: class sample { 24: public function __toString() { 25: return " @#$%Object @#$%"; 26: } 27: } 28: $sample_obj = new sample; 29: 30: // creating a file resource 31: $file_handle = fopen(__FILE__, 'r'); 32: 33: // array with different values 34: $values = array ( 35: 36: // integer values 37: 0, 38: 1, 39: 12345, 40: -2345, 41: 42: // float values 43: 10.5, 44: -10.5, 45: 10.1234567e10, 46: 10.7654321E-10, 47: .5, 48: 49: // array values 50: array(), 51: array(0), 52: array(1), 53: array(1, 2), 54: array('color' => 'red', 'item' => 'pen'), 55: 56: // boolean values 57: true, 58: false, 59: TRUE, 60: FALSE, 61: 62: // empty string 63: "", 64: '', 65: 66: // null vlaues 67: NULL, 68: null, 69: 70: // undefined variable 71: $undefined_var, 72: 73: // unset variable 74: $unset_var, 75: 76: // object 77: $sample_obj, 78: 79: // resource 80: $file_handle 81: ); 82: 83: 84: // loop through each element of the array and check the working of chop() 85: // when $str arugment is supplied with different values 86: 87: echo "\n--- Testing chop() by supplying different values for 'str' argument ---\n"; 88: $counter = 1; 89: for($index = 0; $index < count($values); $index ++) { 90: echo "-- Iteration $counter --\n"; 91: $str = $values [$index]; 92: 93: var_dump( chop($str) ); 94: var_dump( chop($str, $charlist) ); 95: 96: $counter ++; 97: } 98: 99: // closing the resource 100: fclose( $file_handle); 101: 102: echo "Done\n"; 103: ?> 104: --EXPECTF-- 105: *** Testing chop() : with unexpected values for str argument *** 106: 107: Notice: Undefined variable: undefined_var in %s on line %d 108: 109: Notice: Undefined variable: unset_var in %s on line %d 110: 111: --- Testing chop() by supplying different values for 'str' argument --- 112: -- Iteration 1 -- 113: string(1) "0" 114: string(0) "" 115: -- Iteration 2 -- 116: string(1) "1" 117: string(0) "" 118: -- Iteration 3 -- 119: string(5) "12345" 120: string(0) "" 121: -- Iteration 4 -- 122: string(5) "-2345" 123: string(1) "-" 124: -- Iteration 5 -- 125: string(4) "10.5" 126: string(3) "10." 127: -- Iteration 6 -- 128: string(5) "-10.5" 129: string(4) "-10." 130: -- Iteration 7 -- 131: string(12) "101234567000" 132: string(0) "" 133: -- Iteration 8 -- 134: string(13) "1.07654321E-9" 135: string(12) "1.07654321E-" 136: -- Iteration 9 -- 137: string(3) "0.5" 138: string(2) "0." 139: -- Iteration 10 -- 140: 141: Warning: chop() expects parameter 1 to be string, array given in %s on line %d 142: NULL 143: 144: Warning: chop() expects parameter 1 to be string, array given in %s on line %d 145: NULL 146: -- Iteration 11 -- 147: 148: Warning: chop() expects parameter 1 to be string, array given in %s on line %d 149: NULL 150: 151: Warning: chop() expects parameter 1 to be string, array given in %s on line %d 152: NULL 153: -- Iteration 12 -- 154: 155: Warning: chop() expects parameter 1 to be string, array given in %s on line %d 156: NULL 157: 158: Warning: chop() expects parameter 1 to be string, array given in %s on line %d 159: NULL 160: -- Iteration 13 -- 161: 162: Warning: chop() expects parameter 1 to be string, array given in %s on line %d 163: NULL 164: 165: Warning: chop() expects parameter 1 to be string, array given in %s on line %d 166: NULL 167: -- Iteration 14 -- 168: 169: Warning: chop() expects parameter 1 to be string, array given in %s on line %d 170: NULL 171: 172: Warning: chop() expects parameter 1 to be string, array given in %s on line %d 173: NULL 174: -- Iteration 15 -- 175: string(1) "1" 176: string(0) "" 177: -- Iteration 16 -- 178: string(0) "" 179: string(0) "" 180: -- Iteration 17 -- 181: string(1) "1" 182: string(0) "" 183: -- Iteration 18 -- 184: string(0) "" 185: string(0) "" 186: -- Iteration 19 -- 187: string(0) "" 188: string(0) "" 189: -- Iteration 20 -- 190: string(0) "" 191: string(0) "" 192: -- Iteration 21 -- 193: string(0) "" 194: string(0) "" 195: -- Iteration 22 -- 196: string(0) "" 197: string(0) "" 198: -- Iteration 23 -- 199: string(0) "" 200: string(0) "" 201: -- Iteration 24 -- 202: string(0) "" 203: string(0) "" 204: -- Iteration 25 -- 205: string(16) " @#$%Object @#$%" 206: string(11) " @#$%Object" 207: -- Iteration 26 -- 208: 209: Warning: chop() expects parameter 1 to be string, resource given in %s on line %d 210: NULL 211: 212: Warning: chop() expects parameter 1 to be string, resource given in %s on line %d 213: NULL 214: Done