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

1.1       misho       1: --TEST--
                      2: Test array_merge_recursive() function : usage variations - unexpected values for $arr2 argument
                      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:  * Passing non array values to 'arr2' argument of array_merge_recursive() and see 
                     12:  * that the function outputs proper warning messages wherever expected.
                     13: */
                     14: 
                     15: echo "*** Testing array_merge_recursive() : Passing non array values to \$arr2 argument ***\n";
                     16: 
                     17: // initialise the first argument
                     18: $arr1 = array(1, array("hello", 'world'));
                     19: 
                     20: //get an unset variable
                     21: $unset_var = 10;
                     22: unset($unset_var);
                     23: 
                     24: class A
                     25: {
                     26: //  public $var = 10;
                     27:   public function __toString() {
                     28:     return "object";
                     29:   }
                     30: }
                     31: 
                     32: // heredoc string
                     33: $heredoc = <<<EOT
                     34: hello world
                     35: EOT;
                     36: 
                     37: // get a resource variable
                     38: $fp = fopen(__FILE__, "r");
                     39: 
                     40: // unexpected values to be passed to $arr2 argument
                     41: $arrays = array (
                     42: 
                     43:        // int data
                     44: /*1*/  0,
                     45:        1,
                     46:        12345,
                     47:        -2345,
                     48: 
                     49:        // float data
                     50: /*5*/  10.5,
                     51:        -10.5,
                     52:        12.3456789000e10,
                     53:        12.3456789000E-10,
                     54:        .5,
                     55: 
                     56:        // null data
                     57: /*10*/ NULL,
                     58:        null,
                     59: 
                     60:        // boolean data
                     61: /*12*/ true,
                     62:        false,
                     63:        TRUE,
                     64:        FALSE,
                     65: 
                     66:        // empty data
                     67: /*16*/ "",
                     68:        '',
                     69: 
                     70:        // string data
                     71: /*18*/ "string",
                     72:        'string',
                     73:        $heredoc,
                     74: 
                     75:        // undefined data
                     76: /*21*/ @$undefined_var,
                     77: 
                     78:        // unset data
                     79: /*22*/ @$unset_var,
                     80: 
                     81:        // resource variable
                     82: /*23*/ $fp,
                     83: 
                     84:        // object data
                     85: /*24*/ new A()
                     86: );
                     87: 
                     88: // loop through each element of $arrays and check the behavior of array_merge_recursive()
                     89: $iterator = 1;
                     90: foreach($arrays as $arr2) {
                     91:   echo "\n-- Iteration $iterator --";
                     92:   var_dump( array_merge_recursive($arr1, $arr2) );
                     93:   $iterator++;
                     94: }
                     95: 
                     96: // close the file resource used
                     97: fclose($fp);
                     98: 
                     99: echo "Done";
                    100: ?>
                    101: --EXPECTF--
                    102: *** Testing array_merge_recursive() : Passing non array values to $arr2 argument ***
                    103: 
                    104: -- Iteration 1 --
                    105: Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d
                    106: NULL
                    107: 
                    108: -- Iteration 2 --
                    109: Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d
                    110: NULL
                    111: 
                    112: -- Iteration 3 --
                    113: Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d
                    114: NULL
                    115: 
                    116: -- Iteration 4 --
                    117: Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d
                    118: NULL
                    119: 
                    120: -- Iteration 5 --
                    121: Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d
                    122: NULL
                    123: 
                    124: -- Iteration 6 --
                    125: Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d
                    126: NULL
                    127: 
                    128: -- Iteration 7 --
                    129: Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d
                    130: NULL
                    131: 
                    132: -- Iteration 8 --
                    133: Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d
                    134: NULL
                    135: 
                    136: -- Iteration 9 --
                    137: Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d
                    138: NULL
                    139: 
                    140: -- Iteration 10 --
                    141: Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d
                    142: NULL
                    143: 
                    144: -- Iteration 11 --
                    145: Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d
                    146: NULL
                    147: 
                    148: -- Iteration 12 --
                    149: Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d
                    150: NULL
                    151: 
                    152: -- Iteration 13 --
                    153: Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d
                    154: NULL
                    155: 
                    156: -- Iteration 14 --
                    157: Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d
                    158: NULL
                    159: 
                    160: -- Iteration 15 --
                    161: Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d
                    162: NULL
                    163: 
                    164: -- Iteration 16 --
                    165: Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d
                    166: NULL
                    167: 
                    168: -- Iteration 17 --
                    169: Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d
                    170: NULL
                    171: 
                    172: -- Iteration 18 --
                    173: Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d
                    174: NULL
                    175: 
                    176: -- Iteration 19 --
                    177: Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d
                    178: NULL
                    179: 
                    180: -- Iteration 20 --
                    181: Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d
                    182: NULL
                    183: 
                    184: -- Iteration 21 --
                    185: Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d
                    186: NULL
                    187: 
                    188: -- Iteration 22 --
                    189: Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d
                    190: NULL
                    191: 
                    192: -- Iteration 23 --
                    193: Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d
                    194: NULL
                    195: 
                    196: -- Iteration 24 --
                    197: Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d
                    198: NULL
                    199: Done

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