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