1--TEST--
2Test explode() function : usage variations - test values for $string argument
3--FILE--
4<?php
5
6/* Prototype  : array explode  ( string $delimiter  , string $string  [, int $limit  ] )
7 * Description: Split a string by string.
8 * Source code: ext/standard/string.c
9*/
10
11echo "*** Testing explode() function: with unexpected inputs for 'string' argument ***\n";
12
13//get an unset variable
14$unset_var = 'string_val';
15unset($unset_var);
16
17//defining a class
18class sample  {
19  public function __toString() {
20    return "sample object";
21  }
22}
23
24//getting the resource
25$file_handle = fopen(__FILE__, "r");
26
27// array with different values for $string
28$strings =  array (
29
30		  // integer values
31/*1*/	  0,
32		  1,
33		  255,
34		  256,
35	      2147483647,
36		  -2147483648,
37
38		  // float values
39/*7*/	  10.5,
40		  -20.5,
41		  10.1234567e10,
42
43		  // array values
44/*10*/	  array(),
45		  array(0),
46		  array(1, 2),
47
48		  // boolean values
49/*13*/	  true,
50		  false,
51		  TRUE,
52		  FALSE,
53
54		  // null values
55/*17*/	  NULL,
56		  null,
57
58		  // objects
59/*19*/	  new sample(),
60
61		  // resource
62/*20*/	  $file_handle,
63
64		  // undefined variable
65/*21*/	  @$undefined_var,
66
67		  // unset variable
68/*22*/	  @$unset_var
69);
70
71// loop through with each element of the $strings array to test explode() function
72$count = 1;
73$delimiter = " ";
74$limit = 5;
75foreach($strings as $string) {
76  echo "-- Iteration $count --\n";
77  var_dump( explode($delimiter, $string, $limit) );
78  $count ++;
79}
80
81fclose($file_handle);  //closing the file handle
82
83?>
84===DONE===
85--EXPECTF--
86*** Testing explode() function: with unexpected inputs for 'string' argument ***
87-- Iteration 1 --
88array(1) {
89  [0]=>
90  string(1) "0"
91}
92-- Iteration 2 --
93array(1) {
94  [0]=>
95  string(1) "1"
96}
97-- Iteration 3 --
98array(1) {
99  [0]=>
100  string(3) "255"
101}
102-- Iteration 4 --
103array(1) {
104  [0]=>
105  string(3) "256"
106}
107-- Iteration 5 --
108array(1) {
109  [0]=>
110  string(10) "2147483647"
111}
112-- Iteration 6 --
113array(1) {
114  [0]=>
115  string(11) "-2147483648"
116}
117-- Iteration 7 --
118array(1) {
119  [0]=>
120  string(4) "10.5"
121}
122-- Iteration 8 --
123array(1) {
124  [0]=>
125  string(5) "-20.5"
126}
127-- Iteration 9 --
128array(1) {
129  [0]=>
130  string(12) "101234567000"
131}
132-- Iteration 10 --
133
134Warning: explode() expects parameter 2 to be string, array given in %s on line %d
135NULL
136-- Iteration 11 --
137
138Warning: explode() expects parameter 2 to be string, array given in %s on line %d
139NULL
140-- Iteration 12 --
141
142Warning: explode() expects parameter 2 to be string, array given in %s on line %d
143NULL
144-- Iteration 13 --
145array(1) {
146  [0]=>
147  string(1) "1"
148}
149-- Iteration 14 --
150array(1) {
151  [0]=>
152  string(0) ""
153}
154-- Iteration 15 --
155array(1) {
156  [0]=>
157  string(1) "1"
158}
159-- Iteration 16 --
160array(1) {
161  [0]=>
162  string(0) ""
163}
164-- Iteration 17 --
165array(1) {
166  [0]=>
167  string(0) ""
168}
169-- Iteration 18 --
170array(1) {
171  [0]=>
172  string(0) ""
173}
174-- Iteration 19 --
175array(2) {
176  [0]=>
177  string(6) "sample"
178  [1]=>
179  string(6) "object"
180}
181-- Iteration 20 --
182
183Warning: explode() expects parameter 2 to be string, resource given in %s on line %d
184NULL
185-- Iteration 21 --
186array(1) {
187  [0]=>
188  string(0) ""
189}
190-- Iteration 22 --
191array(1) {
192  [0]=>
193  string(0) ""
194}
195===DONE===
196