1--TEST--
2Test chunk_split() function : usage variations - with unexpected values for 'str' argument
3--FILE--
4<?php
5/* Prototype  : string chunk_split(string $str [, int $chunklen [, string $ending]])
6 * Description: Returns split line %d%d
7 * Source code: ext/standard/string.c
8 * Alias to functions: none
9*/
10
11echo "*** Testing chunk_split() : with unexpected values for 'str' argument ***\n";
12
13// Initialising variables
14$chunklen = 2;
15$ending = ' ';
16
17//get an unset variable
18$unset_var = 10;
19unset ($unset_var);
20
21//class for object variable
22class MyClass
23{
24  public function __toString()
25  {
26    return "object";
27  }
28}
29
30//resource  variable
31$fp = fopen(__FILE__, 'r');
32
33//different values for 'str'
34$values = array(
35
36  // int data
37  0,
38  1,
39  12345,
40  -2345,
41
42  // float data
43  10.5,
44  -10.5,
45  10.1234567e10,
46  10.7654321E-10,
47  .5,
48
49  // array data
50  array(),
51  array(0),
52  array(1),
53  array(1, 2),
54  array('color' => 'red', 'item' => 'pen'),
55
56  // null data
57  NULL,
58  null,
59
60  // boolean data
61  true,
62  false,
63  TRUE,
64  FALSE,
65
66  // empty data
67  "",
68  '',
69
70  // string data
71  "string",
72  'string',
73
74  // object data
75  new MyClass(),
76
77  // undefined data
78  @$undefined_var,
79
80  // unset data
81  @$unset_var,
82
83  // resource data
84  $fp
85);
86
87// loop through each element of the array for 'str'
88for($count = 0; $count < count($values); $count++) {
89  echo "-- Iteration ".($count+1)." --\n";
90  var_dump( chunk_split($values[$count], $chunklen, $ending) );
91};
92
93echo "Done";
94
95// close the resource
96fclose($fp);
97
98?>
99--EXPECTF--
100*** Testing chunk_split() : with unexpected values for 'str' argument ***
101-- Iteration 1 --
102string(2) "0 "
103-- Iteration 2 --
104string(2) "1 "
105-- Iteration 3 --
106string(8) "12 34 5 "
107-- Iteration 4 --
108string(8) "-2 34 5 "
109-- Iteration 5 --
110string(6) "10 .5 "
111-- Iteration 6 --
112string(8) "-1 0. 5 "
113-- Iteration 7 --
114string(18) "10 12 34 56 70 00 "
115-- Iteration 8 --
116string(20) "1. 07 65 43 21 E- 9 "
117-- Iteration 9 --
118string(5) "0. 5 "
119-- Iteration 10 --
120
121Warning: chunk_split() expects parameter 1 to be string, array given in %s on line 87
122NULL
123-- Iteration 11 --
124
125Warning: chunk_split() expects parameter 1 to be string, array given in %s on line 87
126NULL
127-- Iteration 12 --
128
129Warning: chunk_split() expects parameter 1 to be string, array given in %s on line 87
130NULL
131-- Iteration 13 --
132
133Warning: chunk_split() expects parameter 1 to be string, array given in %s on line 87
134NULL
135-- Iteration 14 --
136
137Warning: chunk_split() expects parameter 1 to be string, array given in %s on line 87
138NULL
139-- Iteration 15 --
140string(1) " "
141-- Iteration 16 --
142string(1) " "
143-- Iteration 17 --
144string(2) "1 "
145-- Iteration 18 --
146string(1) " "
147-- Iteration 19 --
148string(2) "1 "
149-- Iteration 20 --
150string(1) " "
151-- Iteration 21 --
152string(1) " "
153-- Iteration 22 --
154string(1) " "
155-- Iteration 23 --
156string(9) "st ri ng "
157-- Iteration 24 --
158string(9) "st ri ng "
159-- Iteration 25 --
160string(9) "ob je ct "
161-- Iteration 26 --
162string(1) " "
163-- Iteration 27 --
164string(1) " "
165-- Iteration 28 --
166
167Warning: chunk_split() expects parameter 1 to be string, resource given in %s on line 87
168NULL
169Done
170