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