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