1--TEST-- 2Test 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 14echo "*** 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'; 20unset($unset_var); 21 22// declaring class 23class 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 values 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 argument is supplied with different values 86 87echo "\n--- Testing chop() by supplying different values for 'str' argument ---\n"; 88$counter = 1; 89for($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 100fclose( $file_handle); 101 102echo "Done\n"; 103?> 104--EXPECTF-- 105*** Testing chop() : with unexpected values for str argument *** 106 107Notice: Undefined variable: undefined_var in %s on line %d 108 109Notice: Undefined variable: unset_var in %s on line %d 110 111--- Testing chop() by supplying different values for 'str' argument --- 112-- Iteration 1 -- 113string(1) "0" 114string(0) "" 115-- Iteration 2 -- 116string(1) "1" 117string(0) "" 118-- Iteration 3 -- 119string(5) "12345" 120string(0) "" 121-- Iteration 4 -- 122string(5) "-2345" 123string(1) "-" 124-- Iteration 5 -- 125string(4) "10.5" 126string(3) "10." 127-- Iteration 6 -- 128string(5) "-10.5" 129string(4) "-10." 130-- Iteration 7 -- 131string(12) "101234567000" 132string(0) "" 133-- Iteration 8 -- 134string(13) "1.07654321E-9" 135string(12) "1.07654321E-" 136-- Iteration 9 -- 137string(3) "0.5" 138string(2) "0." 139-- Iteration 10 -- 140 141Warning: chop() expects parameter 1 to be string, array given in %s on line %d 142NULL 143 144Warning: chop() expects parameter 1 to be string, array given in %s on line %d 145NULL 146-- Iteration 11 -- 147 148Warning: chop() expects parameter 1 to be string, array given in %s on line %d 149NULL 150 151Warning: chop() expects parameter 1 to be string, array given in %s on line %d 152NULL 153-- Iteration 12 -- 154 155Warning: chop() expects parameter 1 to be string, array given in %s on line %d 156NULL 157 158Warning: chop() expects parameter 1 to be string, array given in %s on line %d 159NULL 160-- Iteration 13 -- 161 162Warning: chop() expects parameter 1 to be string, array given in %s on line %d 163NULL 164 165Warning: chop() expects parameter 1 to be string, array given in %s on line %d 166NULL 167-- Iteration 14 -- 168 169Warning: chop() expects parameter 1 to be string, array given in %s on line %d 170NULL 171 172Warning: chop() expects parameter 1 to be string, array given in %s on line %d 173NULL 174-- Iteration 15 -- 175string(1) "1" 176string(0) "" 177-- Iteration 16 -- 178string(0) "" 179string(0) "" 180-- Iteration 17 -- 181string(1) "1" 182string(0) "" 183-- Iteration 18 -- 184string(0) "" 185string(0) "" 186-- Iteration 19 -- 187string(0) "" 188string(0) "" 189-- Iteration 20 -- 190string(0) "" 191string(0) "" 192-- Iteration 21 -- 193string(0) "" 194string(0) "" 195-- Iteration 22 -- 196string(0) "" 197string(0) "" 198-- Iteration 23 -- 199string(0) "" 200string(0) "" 201-- Iteration 24 -- 202string(0) "" 203string(0) "" 204-- Iteration 25 -- 205string(16) " @#$%Object @#$%" 206string(11) " @#$%Object" 207-- Iteration 26 -- 208 209Warning: chop() expects parameter 1 to be string, resource given in %s on line %d 210NULL 211 212Warning: chop() expects parameter 1 to be string, resource given in %s on line %d 213NULL 214Done 215