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 vlaues 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 arugment 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 126string(0) "" 127-- Iteration 11 -- 128 129Notice: Array to string conversion in %s on line %d 130string(1) "0" 131-- Iteration 12 -- 132 133Notice: Array to string conversion in %s on line %d 134string(1) "1" 135-- Iteration 13 -- 136 137Notice: Array to string conversion in %s on line %d 138string(7) "1Array2" 139-- Iteration 14 -- 140 141Notice: Array to string conversion in %s on line %d 142string(11) "redArraypen" 143-- Iteration 15 -- 144string(17) "element11element2" 145-- Iteration 16 -- 146string(16) "element1element2" 147-- Iteration 17 -- 148string(17) "element11element2" 149-- Iteration 18 -- 150string(16) "element1element2" 151-- Iteration 19 -- 152string(26) "element1testObjectelement2" 153-- Iteration 20 -- 154string(16) "element1element2" 155-- Iteration 21 -- 156string(16) "element1element2" 157-- Iteration 22 -- 158string(16) "element1element2" 159-- Iteration 23 -- 160string(16) "element1element2" 161-- Iteration 24 -- 162string(%d) "element1Resource id #%delement2" 163-- Iteration 25 -- 164string(16) "element1element2" 165-- Iteration 26 -- 166string(16) "element1element2" 167Done