Annotation of embedaddon/php/ext/standard/tests/array/array_merge_recursive_variation4.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: Test array_merge_recursive() function : usage variations - associative array with different keys
                      3: --FILE--
                      4: <?php
                      5: /* Prototype  : array array_merge_recursive(array $arr1[, array $...])
                      6:  * Description: Recursively merges elements from passed arrays into one array
                      7:  * Source code: ext/standard/array.c
                      8: */
                      9: 
                     10: /*
                     11:  * Testing the functionality of array_merge_recursive() by passing different
                     12:  * associative arrays having different keys to $arr1 argument.
                     13: */
                     14: 
                     15: echo "*** Testing array_merge_recursive() : assoc. array with diff. keys to \$arr1 argument ***\n";
                     16: 
                     17: // get an unset variable
                     18: $unset_var = 10;
                     19: unset ($unset_var);
                     20: 
                     21: // get a resource variable
                     22: $fp = fopen(__FILE__, "r");
                     23: 
                     24: // get a class
                     25: class classA
                     26: {
                     27:   public function __toString(){
                     28:     return "Class A object";
                     29:   }
                     30: }
                     31: 
                     32: // get a heredoc string
                     33: $heredoc = <<<EOT
                     34: Hello world
                     35: EOT;
                     36: 
                     37: // different associative arrays to be passed to $arr1 argument
                     38: $arrays = array (
                     39: /*1*/  // arrays with integer keys
                     40:        array(0 => "0", 1 => array(1 => "one")),
                     41:        array(1 => "1", 2 => array(1 => "one", 2 => "two", 3 => 1, 4 => "4")),
                     42: 
                     43:        // arrays with float keys
                     44: /*3*/  array(2.3333 => "float", 44.44 => array(1.1 => "float")),
                     45:        array(1.2 => "f1", 3.33 => "f2", 4.89999922839999 => array(1.1 => "f1"), 3333333.333333 => "f4"),
                     46: 
                     47:        // arrays with string keys
                     48: /*5*/  array('\tHello' => array("hello", 'world'), '\v\fworld' => 2.2, 'pen\n' => 111),
                     49:        array("\tHello" => array("hello", 'world'), "\v\fworld" => 2.2, "pen\n" => 111),
                     50:        array("hello", $heredoc => array("heredoc", 'string'), "string"),
                     51: 
                     52:        // array with object, unset variable and resource variable
                     53: /*8*/ array(new classA() => 11, @$unset_var => array("unset"), $fp => 'resource', 11, "hello")
                     54: );
                     55: 
                     56: // initialise the second array 
                     57: $arr2 = array( 1 => "one", 2, "string" => "hello", "array" => array("a", "b", "c"));
                     58: 
                     59: // loop through each sub array of $arrays and check the behavior of array_merge_recursive()
                     60: $iterator = 1;
                     61: foreach($arrays as $arr1) {
                     62:   echo "-- Iteration $iterator --\n";
                     63: 
                     64:   // with default argument
                     65:   echo "-- With default argument --\n";
                     66:   var_dump( array_merge_recursive($arr1) );
                     67: 
                     68:   // with more arguments
                     69:   echo "-- With more arguments --\n";
                     70:   var_dump( array_merge_recursive($arr1, $arr2) );
                     71: 
                     72:   $iterator++;
                     73: }
                     74: 
                     75: // close the file resource used
                     76: fclose($fp);
                     77:   
                     78: echo "Done";
                     79: ?>
                     80: --EXPECTF--
                     81: *** Testing array_merge_recursive() : assoc. array with diff. keys to $arr1 argument ***
                     82: 
                     83: Warning: Illegal offset type in %s on line %d
                     84: 
                     85: Warning: Illegal offset type in %s on line %d
                     86: -- Iteration 1 --
                     87: -- With default argument --
                     88: array(2) {
                     89:   [0]=>
                     90:   string(1) "0"
                     91:   [1]=>
                     92:   array(1) {
                     93:     [1]=>
                     94:     string(3) "one"
                     95:   }
                     96: }
                     97: -- With more arguments --
                     98: array(6) {
                     99:   [0]=>
                    100:   string(1) "0"
                    101:   [1]=>
                    102:   array(1) {
                    103:     [1]=>
                    104:     string(3) "one"
                    105:   }
                    106:   [2]=>
                    107:   string(3) "one"
                    108:   [3]=>
                    109:   int(2)
                    110:   ["string"]=>
                    111:   string(5) "hello"
                    112:   ["array"]=>
                    113:   array(3) {
                    114:     [0]=>
                    115:     string(1) "a"
                    116:     [1]=>
                    117:     string(1) "b"
                    118:     [2]=>
                    119:     string(1) "c"
                    120:   }
                    121: }
                    122: -- Iteration 2 --
                    123: -- With default argument --
                    124: array(2) {
                    125:   [0]=>
                    126:   string(1) "1"
                    127:   [1]=>
                    128:   array(4) {
                    129:     [1]=>
                    130:     string(3) "one"
                    131:     [2]=>
                    132:     string(3) "two"
                    133:     [3]=>
                    134:     int(1)
                    135:     [4]=>
                    136:     string(1) "4"
                    137:   }
                    138: }
                    139: -- With more arguments --
                    140: array(6) {
                    141:   [0]=>
                    142:   string(1) "1"
                    143:   [1]=>
                    144:   array(4) {
                    145:     [1]=>
                    146:     string(3) "one"
                    147:     [2]=>
                    148:     string(3) "two"
                    149:     [3]=>
                    150:     int(1)
                    151:     [4]=>
                    152:     string(1) "4"
                    153:   }
                    154:   [2]=>
                    155:   string(3) "one"
                    156:   [3]=>
                    157:   int(2)
                    158:   ["string"]=>
                    159:   string(5) "hello"
                    160:   ["array"]=>
                    161:   array(3) {
                    162:     [0]=>
                    163:     string(1) "a"
                    164:     [1]=>
                    165:     string(1) "b"
                    166:     [2]=>
                    167:     string(1) "c"
                    168:   }
                    169: }
                    170: -- Iteration 3 --
                    171: -- With default argument --
                    172: array(2) {
                    173:   [0]=>
                    174:   string(5) "float"
                    175:   [1]=>
                    176:   array(1) {
                    177:     [1]=>
                    178:     string(5) "float"
                    179:   }
                    180: }
                    181: -- With more arguments --
                    182: array(6) {
                    183:   [0]=>
                    184:   string(5) "float"
                    185:   [1]=>
                    186:   array(1) {
                    187:     [1]=>
                    188:     string(5) "float"
                    189:   }
                    190:   [2]=>
                    191:   string(3) "one"
                    192:   [3]=>
                    193:   int(2)
                    194:   ["string"]=>
                    195:   string(5) "hello"
                    196:   ["array"]=>
                    197:   array(3) {
                    198:     [0]=>
                    199:     string(1) "a"
                    200:     [1]=>
                    201:     string(1) "b"
                    202:     [2]=>
                    203:     string(1) "c"
                    204:   }
                    205: }
                    206: -- Iteration 4 --
                    207: -- With default argument --
                    208: array(4) {
                    209:   [0]=>
                    210:   string(2) "f1"
                    211:   [1]=>
                    212:   string(2) "f2"
                    213:   [2]=>
                    214:   array(1) {
                    215:     [1]=>
                    216:     string(2) "f1"
                    217:   }
                    218:   [3]=>
                    219:   string(2) "f4"
                    220: }
                    221: -- With more arguments --
                    222: array(8) {
                    223:   [0]=>
                    224:   string(2) "f1"
                    225:   [1]=>
                    226:   string(2) "f2"
                    227:   [2]=>
                    228:   array(1) {
                    229:     [1]=>
                    230:     string(2) "f1"
                    231:   }
                    232:   [3]=>
                    233:   string(2) "f4"
                    234:   [4]=>
                    235:   string(3) "one"
                    236:   [5]=>
                    237:   int(2)
                    238:   ["string"]=>
                    239:   string(5) "hello"
                    240:   ["array"]=>
                    241:   array(3) {
                    242:     [0]=>
                    243:     string(1) "a"
                    244:     [1]=>
                    245:     string(1) "b"
                    246:     [2]=>
                    247:     string(1) "c"
                    248:   }
                    249: }
                    250: -- Iteration 5 --
                    251: -- With default argument --
                    252: array(3) {
                    253:   ["\tHello"]=>
                    254:   array(2) {
                    255:     [0]=>
                    256:     string(5) "hello"
                    257:     [1]=>
                    258:     string(5) "world"
                    259:   }
                    260:   ["\v\fworld"]=>
                    261:   float(2.2)
                    262:   ["pen\n"]=>
                    263:   int(111)
                    264: }
                    265: -- With more arguments --
                    266: array(7) {
                    267:   ["\tHello"]=>
                    268:   array(2) {
                    269:     [0]=>
                    270:     string(5) "hello"
                    271:     [1]=>
                    272:     string(5) "world"
                    273:   }
                    274:   ["\v\fworld"]=>
                    275:   float(2.2)
                    276:   ["pen\n"]=>
                    277:   int(111)
                    278:   [0]=>
                    279:   string(3) "one"
                    280:   [1]=>
                    281:   int(2)
                    282:   ["string"]=>
                    283:   string(5) "hello"
                    284:   ["array"]=>
                    285:   array(3) {
                    286:     [0]=>
                    287:     string(1) "a"
                    288:     [1]=>
                    289:     string(1) "b"
                    290:     [2]=>
                    291:     string(1) "c"
                    292:   }
                    293: }
                    294: -- Iteration 6 --
                    295: -- With default argument --
                    296: array(3) {
                    297:   ["   Hello"]=>
                    298:   array(2) {
                    299:     [0]=>
                    300:     string(5) "hello"
                    301:     [1]=>
                    302:     string(5) "world"
                    303:   }
                    304:   ["world"]=>
                    305:   float(2.2)
                    306:   ["pen
                    307: "]=>
                    308:   int(111)
                    309: }
                    310: -- With more arguments --
                    311: array(7) {
                    312:   ["   Hello"]=>
                    313:   array(2) {
                    314:     [0]=>
                    315:     string(5) "hello"
                    316:     [1]=>
                    317:     string(5) "world"
                    318:   }
                    319:   ["world"]=>
                    320:   float(2.2)
                    321:   ["pen
                    322: "]=>
                    323:   int(111)
                    324:   [0]=>
                    325:   string(3) "one"
                    326:   [1]=>
                    327:   int(2)
                    328:   ["string"]=>
                    329:   string(5) "hello"
                    330:   ["array"]=>
                    331:   array(3) {
                    332:     [0]=>
                    333:     string(1) "a"
                    334:     [1]=>
                    335:     string(1) "b"
                    336:     [2]=>
                    337:     string(1) "c"
                    338:   }
                    339: }
                    340: -- Iteration 7 --
                    341: -- With default argument --
                    342: array(3) {
                    343:   [0]=>
                    344:   string(5) "hello"
                    345:   ["Hello world"]=>
                    346:   array(2) {
                    347:     [0]=>
                    348:     string(7) "heredoc"
                    349:     [1]=>
                    350:     string(6) "string"
                    351:   }
                    352:   [1]=>
                    353:   string(6) "string"
                    354: }
                    355: -- With more arguments --
                    356: array(7) {
                    357:   [0]=>
                    358:   string(5) "hello"
                    359:   ["Hello world"]=>
                    360:   array(2) {
                    361:     [0]=>
                    362:     string(7) "heredoc"
                    363:     [1]=>
                    364:     string(6) "string"
                    365:   }
                    366:   [1]=>
                    367:   string(6) "string"
                    368:   [2]=>
                    369:   string(3) "one"
                    370:   [3]=>
                    371:   int(2)
                    372:   ["string"]=>
                    373:   string(5) "hello"
                    374:   ["array"]=>
                    375:   array(3) {
                    376:     [0]=>
                    377:     string(1) "a"
                    378:     [1]=>
                    379:     string(1) "b"
                    380:     [2]=>
                    381:     string(1) "c"
                    382:   }
                    383: }
                    384: -- Iteration 8 --
                    385: -- With default argument --
                    386: array(3) {
                    387:   [""]=>
                    388:   array(1) {
                    389:     [0]=>
                    390:     string(5) "unset"
                    391:   }
                    392:   [0]=>
                    393:   int(11)
                    394:   [1]=>
                    395:   string(5) "hello"
                    396: }
                    397: -- With more arguments --
                    398: array(7) {
                    399:   [""]=>
                    400:   array(1) {
                    401:     [0]=>
                    402:     string(5) "unset"
                    403:   }
                    404:   [0]=>
                    405:   int(11)
                    406:   [1]=>
                    407:   string(5) "hello"
                    408:   [2]=>
                    409:   string(3) "one"
                    410:   [3]=>
                    411:   int(2)
                    412:   ["string"]=>
                    413:   string(5) "hello"
                    414:   ["array"]=>
                    415:   array(3) {
                    416:     [0]=>
                    417:     string(1) "a"
                    418:     [1]=>
                    419:     string(1) "b"
                    420:     [2]=>
                    421:     string(1) "c"
                    422:   }
                    423: }
                    424: Done

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