1--TEST--
2Test chunk_split() function : usage variations - unexpected values for 'chunklen' argument(Bug#42796)
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() : with unexpected values for 'chunklen' argument ***\n";
12
13// Initialise function arguments
14$str = 'This is chuklen variation';
15$ending = '*';
16
17//get an unset variable
18$unset_var = 10;
19unset ($unset_var);
20
21//get resource variable
22$fp = fopen(__FILE__, 'r');
23
24//Class to get object variable
25class MyClass
26{
27   public function __toString() {
28     return "object";
29   }
30}
31
32//array of values to iterate over
33$values = array(
34
35  // float data
36  10.5,
37  -10.5,
38  (float) PHP_INT_MAX + 1,
39  (float) -PHP_INT_MAX - 1,
40  .5,
41
42  // array data
43  array(),
44  array(0),
45  array(1),
46  array(1, 2),
47  array('color' => 'red', 'item' => 'pen'),
48
49  // null data
50  NULL,
51  null,
52
53  // boolean data
54  true,
55  false,
56  TRUE,
57  FALSE,
58
59  // empty data
60  "",
61  '',
62
63  // string data
64  "string",
65  'string',
66
67  // object data
68  new MyClass(),
69
70  // undefined data
71  @$undefined_var,
72
73  // unset data
74  @$unset_var,
75
76  // resource variable
77  $fp
78);
79
80// loop through each element of the values for 'chunklen'
81for($count = 0; $count < count($values); $count++) {
82  echo "-- Iteration ".($count+1)." --\n";
83  var_dump( chunk_split($str, $values[$count], $ending) );
84}
85
86//closing resource
87fclose($fp);
88
89?>
90===DONE===
91--EXPECTF--
92*** Testing chunk_split() : with unexpected values for 'chunklen' argument ***
93-- Iteration 1 --
94string(28) "This is ch*uklen vari*ation*"
95-- Iteration 2 --
96
97Warning: chunk_split(): Chunk length should be greater than zero in %schunk_split_variation2.php on line %d
98bool(false)
99-- Iteration 3 --
100
101Warning: chunk_split(): Chunk length should be greater than zero in %schunk_split_variation2.php on line %d
102bool(false)
103-- Iteration 4 --
104
105Warning: chunk_split(): Chunk length should be greater than zero in %schunk_split_variation2.php on line %d
106bool(false)
107-- Iteration 5 --
108
109Warning: chunk_split(): Chunk length should be greater than zero in %schunk_split_variation2.php on line %d
110bool(false)
111-- Iteration 6 --
112
113Warning: chunk_split() expects parameter 2 to be long, array given in %schunk_split_variation2.php on line %d
114NULL
115-- Iteration 7 --
116
117Warning: chunk_split() expects parameter 2 to be long, array given in %schunk_split_variation2.php on line %d
118NULL
119-- Iteration 8 --
120
121Warning: chunk_split() expects parameter 2 to be long, array given in %schunk_split_variation2.php on line %d
122NULL
123-- Iteration 9 --
124
125Warning: chunk_split() expects parameter 2 to be long, array given in %schunk_split_variation2.php on line %d
126NULL
127-- Iteration 10 --
128
129Warning: chunk_split() expects parameter 2 to be long, array given in %schunk_split_variation2.php on line %d
130NULL
131-- Iteration 11 --
132
133Warning: chunk_split(): Chunk length should be greater than zero in %schunk_split_variation2.php on line %d
134bool(false)
135-- Iteration 12 --
136
137Warning: chunk_split(): Chunk length should be greater than zero in %schunk_split_variation2.php on line %d
138bool(false)
139-- Iteration 13 --
140string(50) "T*h*i*s* *i*s* *c*h*u*k*l*e*n* *v*a*r*i*a*t*i*o*n*"
141-- Iteration 14 --
142
143Warning: chunk_split(): Chunk length should be greater than zero in %schunk_split_variation2.php on line %d
144bool(false)
145-- Iteration 15 --
146string(50) "T*h*i*s* *i*s* *c*h*u*k*l*e*n* *v*a*r*i*a*t*i*o*n*"
147-- Iteration 16 --
148
149Warning: chunk_split(): Chunk length should be greater than zero in %schunk_split_variation2.php on line %d
150bool(false)
151-- Iteration 17 --
152
153Warning: chunk_split() expects parameter 2 to be long, string given in %schunk_split_variation2.php on line %d
154NULL
155-- Iteration 18 --
156
157Warning: chunk_split() expects parameter 2 to be long, string given in %schunk_split_variation2.php on line %d
158NULL
159-- Iteration 19 --
160
161Warning: chunk_split() expects parameter 2 to be long, string given in %schunk_split_variation2.php on line %d
162NULL
163-- Iteration 20 --
164
165Warning: chunk_split() expects parameter 2 to be long, string given in %schunk_split_variation2.php on line %d
166NULL
167-- Iteration 21 --
168
169Warning: chunk_split() expects parameter 2 to be long, object given in %schunk_split_variation2.php on line %d
170NULL
171-- Iteration 22 --
172
173Warning: chunk_split(): Chunk length should be greater than zero in %schunk_split_variation2.php on line %d
174bool(false)
175-- Iteration 23 --
176
177Warning: chunk_split(): Chunk length should be greater than zero in %schunk_split_variation2.php on line %d
178bool(false)
179-- Iteration 24 --
180
181Warning: chunk_split() expects parameter 2 to be long, resource given in %schunk_split_variation2.php on line %d
182NULL
183===DONE===
184