1--TEST-- 2Test str_split() function : usage variations - different integer values for 'split_length' argument 3--FILE-- 4<?php 5/* 6* passing different integer values for 'split_length' argument to str_split() 7*/ 8 9echo "*** Testing str_split() : different integer values for 'split_length' ***\n"; 10//Initialise variables 11$str = 'This is a string with 123 & escape char \t'; 12 13//different values for 'split_length' 14$values = array ( 15 0, 16 1, 17 -123, //negative integer 18 0234, //octal number 19 0x1A, //hexadecimal number 20 2147483647, //max positive integer number 21 -2147483648, //min negative integer 22); 23 24//loop through each element of $values for 'split_length' 25for($count = 0; $count < count($values); $count++) { 26 echo "-- Iteration ".($count + 1)." --\n"; 27 28 try { 29 var_dump( str_split($str, $values[$count]) ); 30 } catch (\ValueError $e) { 31 echo $e->getMessage() . "\n"; 32 } 33} 34?> 35--EXPECT-- 36*** Testing str_split() : different integer values for 'split_length' *** 37-- Iteration 1 -- 38str_split(): Argument #2 ($length) must be greater than 0 39-- Iteration 2 -- 40array(42) { 41 [0]=> 42 string(1) "T" 43 [1]=> 44 string(1) "h" 45 [2]=> 46 string(1) "i" 47 [3]=> 48 string(1) "s" 49 [4]=> 50 string(1) " " 51 [5]=> 52 string(1) "i" 53 [6]=> 54 string(1) "s" 55 [7]=> 56 string(1) " " 57 [8]=> 58 string(1) "a" 59 [9]=> 60 string(1) " " 61 [10]=> 62 string(1) "s" 63 [11]=> 64 string(1) "t" 65 [12]=> 66 string(1) "r" 67 [13]=> 68 string(1) "i" 69 [14]=> 70 string(1) "n" 71 [15]=> 72 string(1) "g" 73 [16]=> 74 string(1) " " 75 [17]=> 76 string(1) "w" 77 [18]=> 78 string(1) "i" 79 [19]=> 80 string(1) "t" 81 [20]=> 82 string(1) "h" 83 [21]=> 84 string(1) " " 85 [22]=> 86 string(1) "1" 87 [23]=> 88 string(1) "2" 89 [24]=> 90 string(1) "3" 91 [25]=> 92 string(1) " " 93 [26]=> 94 string(1) "&" 95 [27]=> 96 string(1) " " 97 [28]=> 98 string(1) "e" 99 [29]=> 100 string(1) "s" 101 [30]=> 102 string(1) "c" 103 [31]=> 104 string(1) "a" 105 [32]=> 106 string(1) "p" 107 [33]=> 108 string(1) "e" 109 [34]=> 110 string(1) " " 111 [35]=> 112 string(1) "c" 113 [36]=> 114 string(1) "h" 115 [37]=> 116 string(1) "a" 117 [38]=> 118 string(1) "r" 119 [39]=> 120 string(1) " " 121 [40]=> 122 string(1) "\" 123 [41]=> 124 string(1) "t" 125} 126-- Iteration 3 -- 127str_split(): Argument #2 ($length) must be greater than 0 128-- Iteration 4 -- 129array(1) { 130 [0]=> 131 string(42) "This is a string with 123 & escape char \t" 132} 133-- Iteration 5 -- 134array(2) { 135 [0]=> 136 string(26) "This is a string with 123 " 137 [1]=> 138 string(16) "& escape char \t" 139} 140-- Iteration 6 -- 141array(1) { 142 [0]=> 143 string(42) "This is a string with 123 & escape char \t" 144} 145-- Iteration 7 -- 146str_split(): Argument #2 ($length) must be greater than 0 147