1--TEST--
2Test str_split() function : usage variations - different integer values for 'split_length' argument
3--SKIPIF--
4<?php
5if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only");
6?>
7--FILE--
8<?php
9/* Prototype  : array str_split(string $str [, int $split_length])
10 * Description: Convert a string to an array. If split_length is
11                specified, break the string down into chunks each
12                split_length characters long.
13 * Source code: ext/standard/string.c
14 * Alias to functions: none
15*/
16
17/*
18* passing different integer values for 'split_length' argument to str_split()
19*/
20
21echo "*** Testing str_split() : different intger values for 'split_length' ***\n";
22//Initialise variables
23$str = 'This is a string with 123 & escape char \t';
24
25//different values for 'split_length'
26$values = array (
27  0,
28  1,
29  -123,  //negative integer
30  0234,  //octal number
31  0x1A,  //hexadecimal number
32  2147483647,  //max positive integer number
33  2147483648,  //max positive integer+1
34  -2147483648,  //min negative integer
35);
36
37//loop through each element of $values for 'split_length'
38for($count = 0; $count < count($values); $count++) {
39  echo "-- Iteration ".($count + 1)." --\n";
40  var_dump( str_split($str, $values[$count]) );
41}
42echo "Done"
43?>
44--EXPECTF--
45*** Testing str_split() : different intger values for 'split_length' ***
46-- Iteration 1 --
47
48Warning: str_split(): The length of each segment must be greater than zero in %s on line %d
49bool(false)
50-- Iteration 2 --
51array(42) {
52  [0]=>
53  string(1) "T"
54  [1]=>
55  string(1) "h"
56  [2]=>
57  string(1) "i"
58  [3]=>
59  string(1) "s"
60  [4]=>
61  string(1) " "
62  [5]=>
63  string(1) "i"
64  [6]=>
65  string(1) "s"
66  [7]=>
67  string(1) " "
68  [8]=>
69  string(1) "a"
70  [9]=>
71  string(1) " "
72  [10]=>
73  string(1) "s"
74  [11]=>
75  string(1) "t"
76  [12]=>
77  string(1) "r"
78  [13]=>
79  string(1) "i"
80  [14]=>
81  string(1) "n"
82  [15]=>
83  string(1) "g"
84  [16]=>
85  string(1) " "
86  [17]=>
87  string(1) "w"
88  [18]=>
89  string(1) "i"
90  [19]=>
91  string(1) "t"
92  [20]=>
93  string(1) "h"
94  [21]=>
95  string(1) " "
96  [22]=>
97  string(1) "1"
98  [23]=>
99  string(1) "2"
100  [24]=>
101  string(1) "3"
102  [25]=>
103  string(1) " "
104  [26]=>
105  string(1) "&"
106  [27]=>
107  string(1) " "
108  [28]=>
109  string(1) "e"
110  [29]=>
111  string(1) "s"
112  [30]=>
113  string(1) "c"
114  [31]=>
115  string(1) "a"
116  [32]=>
117  string(1) "p"
118  [33]=>
119  string(1) "e"
120  [34]=>
121  string(1) " "
122  [35]=>
123  string(1) "c"
124  [36]=>
125  string(1) "h"
126  [37]=>
127  string(1) "a"
128  [38]=>
129  string(1) "r"
130  [39]=>
131  string(1) " "
132  [40]=>
133  string(1) "\"
134  [41]=>
135  string(1) "t"
136}
137-- Iteration 3 --
138
139Warning: str_split(): The length of each segment must be greater than zero in %s on line %d
140bool(false)
141-- Iteration 4 --
142array(1) {
143  [0]=>
144  string(42) "This is a string with 123 & escape char \t"
145}
146-- Iteration 5 --
147array(2) {
148  [0]=>
149  string(26) "This is a string with 123 "
150  [1]=>
151  string(16) "& escape char \t"
152}
153-- Iteration 6 --
154array(1) {
155  [0]=>
156  string(42) "This is a string with 123 & escape char \t"
157}
158-- Iteration 7 --
159array(1) {
160  [0]=>
161  string(42) "This is a string with 123 & escape char \t"
162}
163-- Iteration 8 --
164
165Warning: str_split(): The length of each segment must be greater than zero in %s on line %d
166bool(false)
167Done
168