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