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