1--TEST--
2Test join() function : usage variations - unexpected values for 'pieces' argument(Bug#42789)
3--FILE--
4<?php
5/* Prototype  : string join( string $glue, array $pieces )
6 * Description: Join array elements with a string
7 * Source code: ext/standard/string.c
8 * Alias of function: implode()
9*/
10
11/*
12 * test join() by passing different unexpected value for pieces argument
13*/
14
15echo "*** Testing join() : usage variations ***\n";
16// initialize all required variables
17$glue = '::';
18
19// get an unset variable
20$unset_var = array(1, 2);
21unset($unset_var);
22
23// get a resouce variable
24$fp = fopen(__FILE__, "r");
25
26// define a class
27class test
28{
29  var $t = 10;
30  var $p = 10;
31  function __toString() {
32    return "testObject";
33  }
34}
35
36// array with different values
37$values =  array (
38
39  // integer values
40  0,
41  1,
42  12345,
43  -2345,
44
45  // float values
46  10.5,
47  -10.5,
48  10.5e10,
49  10.6E-10,
50  .5,
51
52  // boolean values
53  true,
54  false,
55  TRUE,
56  FALSE,
57
58  // string values
59  "string",
60  'string',
61
62  // objects
63  new test(),
64
65  // empty string
66  "",
67  '',
68
69  // null vlaues
70  NULL,
71  null,
72
73  // resource variable
74  $fp,
75
76  // undefined variable
77  @$undefined_var,
78
79  // unset variable
80  @$unset_var
81);
82
83
84// loop through each element of the array and check the working of join()
85// when $pieces argument is supplied with different values
86echo "\n--- Testing join() by supplying different values for 'pieces' argument ---\n";
87$counter = 1;
88for($index = 0; $index < count($values); $index ++) {
89  echo "-- Iteration $counter --\n";
90  $pieces = $values [$index];
91
92  var_dump( join($glue, $pieces) );
93
94  $counter ++;
95}
96
97// close the resources used
98fclose($fp);
99
100echo "Done\n";
101?>
102--EXPECTF--
103*** Testing join() : usage variations ***
104
105--- Testing join() by supplying different values for 'pieces' argument ---
106-- Iteration 1 --
107
108Warning: join(): Invalid arguments passed in %s on line %d
109NULL
110-- Iteration 2 --
111
112Warning: join(): Invalid arguments passed in %s on line %d
113NULL
114-- Iteration 3 --
115
116Warning: join(): Invalid arguments passed in %s on line %d
117NULL
118-- Iteration 4 --
119
120Warning: join(): Invalid arguments passed in %s on line %d
121NULL
122-- Iteration 5 --
123
124Warning: join(): Invalid arguments passed in %s on line %d
125NULL
126-- Iteration 6 --
127
128Warning: join(): Invalid arguments passed in %s on line %d
129NULL
130-- Iteration 7 --
131
132Warning: join(): Invalid arguments passed in %s on line %d
133NULL
134-- Iteration 8 --
135
136Warning: join(): Invalid arguments passed in %s on line %d
137NULL
138-- Iteration 9 --
139
140Warning: join(): Invalid arguments passed in %s on line %d
141NULL
142-- Iteration 10 --
143
144Warning: join(): Invalid arguments passed in %s on line %d
145NULL
146-- Iteration 11 --
147
148Warning: join(): Invalid arguments passed in %s on line %d
149NULL
150-- Iteration 12 --
151
152Warning: join(): Invalid arguments passed in %s on line %d
153NULL
154-- Iteration 13 --
155
156Warning: join(): Invalid arguments passed in %s on line %d
157NULL
158-- Iteration 14 --
159
160Warning: join(): Invalid arguments passed in %s on line %d
161NULL
162-- Iteration 15 --
163
164Warning: join(): Invalid arguments passed in %s on line %d
165NULL
166-- Iteration 16 --
167
168Warning: join(): Invalid arguments passed in %s on line %d
169NULL
170-- Iteration 17 --
171
172Warning: join(): Invalid arguments passed in %s on line %d
173NULL
174-- Iteration 18 --
175
176Warning: join(): Invalid arguments passed in %s on line %d
177NULL
178-- Iteration 19 --
179
180Warning: join(): Invalid arguments passed in %s on line %d
181NULL
182-- Iteration 20 --
183
184Warning: join(): Invalid arguments passed in %s on line %d
185NULL
186-- Iteration 21 --
187
188Warning: join(): Invalid arguments passed in %s on line %d
189NULL
190-- Iteration 22 --
191
192Warning: join(): Invalid arguments passed in %s on line %d
193NULL
194-- Iteration 23 --
195
196Warning: join(): Invalid arguments passed in %s on line %d
197NULL
198Done
199