Annotation of embedaddon/php/ext/standard/tests/strings/join_variation1.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: Test 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: 
                     15: echo "*** 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';
                     21: unset($unset_var);
                     22: 
                     23: // get a resource variable
                     24: $fp = fopen(__FILE__, "r");
                     25: 
                     26: // define a class
                     27: class 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
                     88: echo "\n--- Testing join() by supplying different values for 'glue' argument ---\n";
                     89: $counter = 1;
                     90: for($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: 
                     99: echo "Done\n";
                    100: ?>
                    101: --EXPECTF--
                    102: *** Testing join() : usage variations ***
                    103: 
                    104: --- Testing join() by supplying different values for 'glue' argument ---
                    105: -- Iteration 1 --
                    106: string(17) "element10element2"
                    107: -- Iteration 2 --
                    108: string(17) "element11element2"
                    109: -- Iteration 3 --
                    110: string(21) "element112345element2"
                    111: -- Iteration 4 --
                    112: string(21) "element1-2345element2"
                    113: -- Iteration 5 --
                    114: string(20) "element110.5element2"
                    115: -- Iteration 6 --
                    116: string(21) "element1-10.5element2"
                    117: -- Iteration 7 --
                    118: string(28) "element1101234567000element2"
                    119: -- Iteration 8 --
                    120: string(29) "element11.07654321E-9element2"
                    121: -- Iteration 9 --
                    122: string(19) "element10.5element2"
                    123: -- Iteration 10 --
                    124: 
                    125: Notice: Array to string conversion in %s on line %d
                    126: string(0) ""
                    127: -- Iteration 11 --
                    128: 
                    129: Notice: Array to string conversion in %s on line %d
                    130: string(1) "0"
                    131: -- Iteration 12 --
                    132: 
                    133: Notice: Array to string conversion in %s on line %d
                    134: string(1) "1"
                    135: -- Iteration 13 --
                    136: 
                    137: Notice: Array to string conversion in %s on line %d
                    138: string(7) "1Array2"
                    139: -- Iteration 14 --
                    140: 
                    141: Notice: Array to string conversion in %s on line %d
                    142: string(11) "redArraypen"
                    143: -- Iteration 15 --
                    144: string(17) "element11element2"
                    145: -- Iteration 16 --
                    146: string(16) "element1element2"
                    147: -- Iteration 17 --
                    148: string(17) "element11element2"
                    149: -- Iteration 18 --
                    150: string(16) "element1element2"
                    151: -- Iteration 19 --
                    152: string(26) "element1testObjectelement2"
                    153: -- Iteration 20 --
                    154: string(16) "element1element2"
                    155: -- Iteration 21 --
                    156: string(16) "element1element2"
                    157: -- Iteration 22 --
                    158: string(16) "element1element2"
                    159: -- Iteration 23 --
                    160: string(16) "element1element2"
                    161: -- Iteration 24 --
                    162: string(%d) "element1Resource id #%delement2"
                    163: -- Iteration 25 --
                    164: string(16) "element1element2"
                    165: -- Iteration 26 --
                    166: string(16) "element1element2"
                    167: Done

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>