1--TEST-- 2Test 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 11echo "*** 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; 19unset ($unset_var); 20 21//resource variable 22$fp = fopen(__FILE__,'r'); 23 24//Class to get object variable 25class 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' 84for($count = 0; $count < count($values); $count++) { 85 echo "-- Iteration ".($count+1)." --\n"; 86 var_dump( chunk_split($str, $chunklen, $values[$count]) ); 87} 88 89echo "Done"; 90 91//closing resource 92fclose($fp); 93?> 94--EXPECTF-- 95*** Testing chunk_split() : unexpected values for 'ending' *** 96-- Iteration 1 -- 97string(28) "This0 is 0simp0le s0trin0g.0" 98-- Iteration 2 -- 99string(28) "This1 is 1simp1le s1trin1g.1" 100-- Iteration 3 -- 101string(52) "This12345 is 12345simp12345le s12345trin12345g.12345" 102-- Iteration 4 -- 103string(52) "This-2345 is -2345simp-2345le s-2345trin-2345g.-2345" 104-- Iteration 5 -- 105string(46) "This10.5 is 10.5simp10.5le s10.5trin10.5g.10.5" 106-- Iteration 6 -- 107string(52) "This-10.5 is -10.5simp-10.5le s-10.5trin-10.5g.-10.5" 108-- Iteration 7 -- 109string(94) "This101234560000 is 101234560000simp101234560000le s101234560000trin101234560000g.101234560000" 110-- Iteration 8 -- 111string(100) "This1.07654321E-9 is 1.07654321E-9simp1.07654321E-9le s1.07654321E-9trin1.07654321E-9g.1.07654321E-9" 112-- Iteration 9 -- 113string(40) "This0.5 is 0.5simp0.5le s0.5trin0.5g.0.5" 114-- Iteration 10 -- 115 116Warning: chunk_split() expects parameter 3 to be string, array given in %s on line %d 117NULL 118-- Iteration 11 -- 119 120Warning: chunk_split() expects parameter 3 to be string, array given in %s on line %d 121NULL 122-- Iteration 12 -- 123 124Warning: chunk_split() expects parameter 3 to be string, array given in %s on line %d 125NULL 126-- Iteration 13 -- 127 128Warning: chunk_split() expects parameter 3 to be string, array given in %s on line %d 129NULL 130-- Iteration 14 -- 131 132Warning: chunk_split() expects parameter 3 to be string, array given in %s on line %d 133NULL 134-- Iteration 15 -- 135string(22) "This is simple string." 136-- Iteration 16 -- 137string(22) "This is simple string." 138-- Iteration 17 -- 139string(28) "This1 is 1simp1le s1trin1g.1" 140-- Iteration 18 -- 141string(22) "This is simple string." 142-- Iteration 19 -- 143string(28) "This1 is 1simp1le s1trin1g.1" 144-- Iteration 20 -- 145string(22) "This is simple string." 146-- Iteration 21 -- 147string(22) "This is simple string." 148-- Iteration 22 -- 149string(22) "This is simple string." 150-- Iteration 23 -- 151string(58) "Thisobject is objectsimpobjectle sobjecttrinobjectg.object" 152-- Iteration 24 -- 153string(22) "This is simple string." 154-- Iteration 25 -- 155string(22) "This is simple string." 156-- Iteration 26 -- 157 158Warning: chunk_split() expects parameter 3 to be string, resource given in %s on line %d 159NULL 160Done