1--TEST--
2Test join() function : usage variations - unexpected values for 'pieces' argument(Bug#42789)
3--FILE--
4<?php
5/*
6 * test join() by passing different unexpected value for pieces argument
7*/
8
9echo "*** Testing join() : usage variations ***\n";
10// initialize all required variables
11$glue = '::';
12
13// get an unset variable
14$unset_var = array(1, 2);
15unset($unset_var);
16
17// get a resource variable
18$fp = fopen(__FILE__, "r");
19
20// define a class
21class test
22{
23  var $t = 10;
24  var $p = 10;
25  function __toString() {
26    return "testObject";
27  }
28}
29
30// array with different values
31$values =  array (
32
33  // integer values
34  0,
35  1,
36  12345,
37  -2345,
38
39  // float values
40  10.5,
41  -10.5,
42  10.5e10,
43  10.6E-10,
44  .5,
45
46  // boolean values
47  true,
48  false,
49  TRUE,
50  FALSE,
51
52  // string values
53  "string",
54  'string',
55
56  // objects
57  new test(),
58
59  // empty string
60  "",
61  '',
62
63  // null values
64  NULL,
65  null,
66
67  // resource variable
68  $fp,
69
70  // undefined variable
71  @$undefined_var,
72
73  // unset variable
74  @$unset_var
75);
76
77
78// loop through each element of the array and check the working of join()
79// when $pieces argument is supplied with different values
80echo "\n--- Testing join() by supplying different values for 'pieces' argument ---\n";
81$counter = 1;
82for($index = 0; $index < count($values); $index ++) {
83    echo "-- Iteration $counter --\n";
84    $pieces = $values [$index];
85
86    try {
87        var_dump( join($glue, $pieces) );
88    } catch (TypeError $e) {
89        echo $e->getMessage(), "\n";
90    }
91
92    $counter ++;
93}
94
95// close the resources used
96fclose($fp);
97
98echo "Done\n";
99?>
100--EXPECT--
101*** Testing join() : usage variations ***
102
103--- Testing join() by supplying different values for 'pieces' argument ---
104-- Iteration 1 --
105join(): Argument #2 ($array) must be of type ?array, int given
106-- Iteration 2 --
107join(): Argument #2 ($array) must be of type ?array, int given
108-- Iteration 3 --
109join(): Argument #2 ($array) must be of type ?array, int given
110-- Iteration 4 --
111join(): Argument #2 ($array) must be of type ?array, int given
112-- Iteration 5 --
113join(): Argument #2 ($array) must be of type ?array, float given
114-- Iteration 6 --
115join(): Argument #2 ($array) must be of type ?array, float given
116-- Iteration 7 --
117join(): Argument #2 ($array) must be of type ?array, float given
118-- Iteration 8 --
119join(): Argument #2 ($array) must be of type ?array, float given
120-- Iteration 9 --
121join(): Argument #2 ($array) must be of type ?array, float given
122-- Iteration 10 --
123join(): Argument #2 ($array) must be of type ?array, bool given
124-- Iteration 11 --
125join(): Argument #2 ($array) must be of type ?array, bool given
126-- Iteration 12 --
127join(): Argument #2 ($array) must be of type ?array, bool given
128-- Iteration 13 --
129join(): Argument #2 ($array) must be of type ?array, bool given
130-- Iteration 14 --
131join(): Argument #2 ($array) must be of type ?array, string given
132-- Iteration 15 --
133join(): Argument #2 ($array) must be of type ?array, string given
134-- Iteration 16 --
135join(): Argument #2 ($array) must be of type ?array, test given
136-- Iteration 17 --
137join(): Argument #2 ($array) must be of type ?array, string given
138-- Iteration 18 --
139join(): Argument #2 ($array) must be of type ?array, string given
140-- Iteration 19 --
141join(): Argument #1 ($array) must be of type array, string given
142-- Iteration 20 --
143join(): Argument #1 ($array) must be of type array, string given
144-- Iteration 21 --
145join(): Argument #2 ($array) must be of type ?array, resource given
146-- Iteration 22 --
147join(): Argument #1 ($array) must be of type array, string given
148-- Iteration 23 --
149join(): Argument #1 ($array) must be of type array, string given
150Done
151