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