1--TEST-- 2Test wordwrap() function : usage variations - unexpected values for str argument 3--FILE-- 4<?php 5/* Prototype : string wordwrap ( string $str [, int $width [, string $break [, bool $cut]]] ) 6 * Description: Wraps buffer to selected number of characters using string break char 7 * Source code: ext/standard/string.c 8*/ 9 10/* 11 * testing wordwrap() by providing different values for str argument 12*/ 13 14echo "*** Testing wordwrap() : usage variations ***\n"; 15// initialize all required variables 16$width = 3; 17$break = '<br />\n'; 18$cut = true; 19 20// resource variable 21$fp = fopen(__FILE__, "r"); 22 23// get an unset variable 24$unset_var = 'string_val'; 25unset($unset_var); 26 27// array with different values 28$values = array ( 29 30 // integer values 31 0, 32 1, 33 12345, 34 -2345, 35 36 // float values 37 10.5, 38 -10.5, 39 10.1234567e10, 40 10.7654321E-10, 41 .5, 42 43 // array values 44 array(), 45 array(0), 46 array(1), 47 array(1, 2), 48 array('color' => 'red', 'item' => 'pen'), 49 50 // boolean values 51 true, 52 false, 53 TRUE, 54 FALSE, 55 56 // objects 57 new stdclass(), 58 59 // Null 60 NULL, 61 null, 62 63 // empty string 64 "", 65 '', 66 67 // resource variable 68 $fp, 69 70 // undefined variable 71 @$undefined_var, 72 73 // unset variable 74 @$unset_var 75); 76 77// loop though each element of the array and check the working of wordwrap() 78// when $str argument is supplied with different values 79echo "\n--- Testing wordwrap() by supplying different values for 'str' argument ---\n"; 80$counter = 1; 81for($index = 0; $index < count($values); $index ++) { 82 echo "-- Iteration $counter --\n"; 83 $str = $values [$index]; 84 85 var_dump( wordwrap($str) ); 86 var_dump( wordwrap($str, $width) ); 87 var_dump( wordwrap($str, $width, $break) ); 88 89 // $cut as false 90 $cut = false; 91 var_dump( wordwrap($str, $width, $break, $cut) ); 92 93 // $cut as true 94 $cut = true; 95 var_dump( wordwrap($str, $width, $break, $cut) ); 96 97 $counter ++; 98} 99 100// close the resource 101fclose($fp); 102 103echo "Done\n"; 104?> 105--EXPECTF-- 106*** Testing wordwrap() : usage variations *** 107 108--- Testing wordwrap() by supplying different values for 'str' argument --- 109-- Iteration 1 -- 110string(1) "0" 111string(1) "0" 112string(1) "0" 113string(1) "0" 114string(1) "0" 115-- Iteration 2 -- 116string(1) "1" 117string(1) "1" 118string(1) "1" 119string(1) "1" 120string(1) "1" 121-- Iteration 3 -- 122string(5) "12345" 123string(5) "12345" 124string(5) "12345" 125string(5) "12345" 126string(13) "123<br />\n45" 127-- Iteration 4 -- 128string(5) "-2345" 129string(5) "-2345" 130string(5) "-2345" 131string(5) "-2345" 132string(13) "-23<br />\n45" 133-- Iteration 5 -- 134string(4) "10.5" 135string(4) "10.5" 136string(4) "10.5" 137string(4) "10.5" 138string(12) "10.<br />\n5" 139-- Iteration 6 -- 140string(5) "-10.5" 141string(5) "-10.5" 142string(5) "-10.5" 143string(5) "-10.5" 144string(13) "-10<br />\n.5" 145-- Iteration 7 -- 146string(12) "101234567000" 147string(12) "101234567000" 148string(12) "101234567000" 149string(12) "101234567000" 150string(36) "101<br />\n234<br />\n567<br />\n000" 151-- Iteration 8 -- 152string(13) "1.07654321E-9" 153string(13) "1.07654321E-9" 154string(13) "1.07654321E-9" 155string(13) "1.07654321E-9" 156string(45) "1.0<br />\n765<br />\n432<br />\n1E-<br />\n9" 157-- Iteration 9 -- 158string(3) "0.5" 159string(3) "0.5" 160string(3) "0.5" 161string(3) "0.5" 162string(3) "0.5" 163-- Iteration 10 -- 164 165Warning: wordwrap() expects parameter 1 to be string, array given in %s on line %d 166NULL 167 168Warning: wordwrap() expects parameter 1 to be string, array given in %s on line %d 169NULL 170 171Warning: wordwrap() expects parameter 1 to be string, array given in %s on line %d 172NULL 173 174Warning: wordwrap() expects parameter 1 to be string, array given in %s on line %d 175NULL 176 177Warning: wordwrap() expects parameter 1 to be string, array given in %s on line %d 178NULL 179-- Iteration 11 -- 180 181Warning: wordwrap() expects parameter 1 to be string, array given in %s on line %d 182NULL 183 184Warning: wordwrap() expects parameter 1 to be string, array given in %s on line %d 185NULL 186 187Warning: wordwrap() expects parameter 1 to be string, array given in %s on line %d 188NULL 189 190Warning: wordwrap() expects parameter 1 to be string, array given in %s on line %d 191NULL 192 193Warning: wordwrap() expects parameter 1 to be string, array given in %s on line %d 194NULL 195-- Iteration 12 -- 196 197Warning: wordwrap() expects parameter 1 to be string, array given in %s on line %d 198NULL 199 200Warning: wordwrap() expects parameter 1 to be string, array given in %s on line %d 201NULL 202 203Warning: wordwrap() expects parameter 1 to be string, array given in %s on line %d 204NULL 205 206Warning: wordwrap() expects parameter 1 to be string, array given in %s on line %d 207NULL 208 209Warning: wordwrap() expects parameter 1 to be string, array given in %s on line %d 210NULL 211-- Iteration 13 -- 212 213Warning: wordwrap() expects parameter 1 to be string, array given in %s on line %d 214NULL 215 216Warning: wordwrap() expects parameter 1 to be string, array given in %s on line %d 217NULL 218 219Warning: wordwrap() expects parameter 1 to be string, array given in %s on line %d 220NULL 221 222Warning: wordwrap() expects parameter 1 to be string, array given in %s on line %d 223NULL 224 225Warning: wordwrap() expects parameter 1 to be string, array given in %s on line %d 226NULL 227-- Iteration 14 -- 228 229Warning: wordwrap() expects parameter 1 to be string, array given in %s on line %d 230NULL 231 232Warning: wordwrap() expects parameter 1 to be string, array given in %s on line %d 233NULL 234 235Warning: wordwrap() expects parameter 1 to be string, array given in %s on line %d 236NULL 237 238Warning: wordwrap() expects parameter 1 to be string, array given in %s on line %d 239NULL 240 241Warning: wordwrap() expects parameter 1 to be string, array given in %s on line %d 242NULL 243-- Iteration 15 -- 244string(1) "1" 245string(1) "1" 246string(1) "1" 247string(1) "1" 248string(1) "1" 249-- Iteration 16 -- 250string(0) "" 251string(0) "" 252string(0) "" 253string(0) "" 254string(0) "" 255-- Iteration 17 -- 256string(1) "1" 257string(1) "1" 258string(1) "1" 259string(1) "1" 260string(1) "1" 261-- Iteration 18 -- 262string(0) "" 263string(0) "" 264string(0) "" 265string(0) "" 266string(0) "" 267-- Iteration 19 -- 268 269Warning: wordwrap() expects parameter 1 to be string, object given in %s on line %d 270NULL 271 272Warning: wordwrap() expects parameter 1 to be string, object given in %s on line %d 273NULL 274 275Warning: wordwrap() expects parameter 1 to be string, object given in %s on line %d 276NULL 277 278Warning: wordwrap() expects parameter 1 to be string, object given in %s on line %d 279NULL 280 281Warning: wordwrap() expects parameter 1 to be string, object given in %s on line %d 282NULL 283-- Iteration 20 -- 284string(0) "" 285string(0) "" 286string(0) "" 287string(0) "" 288string(0) "" 289-- Iteration 21 -- 290string(0) "" 291string(0) "" 292string(0) "" 293string(0) "" 294string(0) "" 295-- Iteration 22 -- 296string(0) "" 297string(0) "" 298string(0) "" 299string(0) "" 300string(0) "" 301-- Iteration 23 -- 302string(0) "" 303string(0) "" 304string(0) "" 305string(0) "" 306string(0) "" 307-- Iteration 24 -- 308 309Warning: wordwrap() expects parameter 1 to be string, resource given in %s on line %d 310NULL 311 312Warning: wordwrap() expects parameter 1 to be string, resource given in %s on line %d 313NULL 314 315Warning: wordwrap() expects parameter 1 to be string, resource given in %s on line %d 316NULL 317 318Warning: wordwrap() expects parameter 1 to be string, resource given in %s on line %d 319NULL 320 321Warning: wordwrap() expects parameter 1 to be string, resource given in %s on line %d 322NULL 323-- Iteration 25 -- 324string(0) "" 325string(0) "" 326string(0) "" 327string(0) "" 328string(0) "" 329-- Iteration 26 -- 330string(0) "" 331string(0) "" 332string(0) "" 333string(0) "" 334string(0) "" 335Done