Annotation of embedaddon/php/ext/standard/tests/array/array_merge_variation2.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: Test array_merge() function : usage variations - Pass different data types as $arr2 arg
! 3: --FILE--
! 4: <?php
! 5: /* Prototype : array array_merge(array $arr1, array $arr2 [, array $...])
! 6: * Description: Merges elements from passed arrays into one array
! 7: * Source code: ext/standard/array.c
! 8: */
! 9:
! 10: /*
! 11: * Pass different data types as $arr2 argument to array_merge() to test behaviour
! 12: */
! 13:
! 14: echo "*** Testing array_merge() : usage variations ***\n";
! 15:
! 16: // Initialise function arguments not being substituted
! 17: $arr1 = array (1, 2);
! 18:
! 19: //get an unset variable
! 20: $unset_var = 10;
! 21: unset ($unset_var);
! 22:
! 23: // get a class
! 24: class classA
! 25: {
! 26: public function __toString() {
! 27: return "Class A object";
! 28: }
! 29: }
! 30:
! 31: // heredoc string
! 32: $heredoc = <<<EOT
! 33: hello world
! 34: EOT;
! 35:
! 36: // get a resource variable
! 37: $fp = fopen(__FILE__, "r");
! 38:
! 39: // unexpected values to be passed to $arr2 argument
! 40: $inputs = array(
! 41:
! 42: // int data
! 43: /*1*/ 0,
! 44: 1,
! 45: 12345,
! 46: -2345,
! 47:
! 48: // float data
! 49: /*5*/ 10.5,
! 50: -10.5,
! 51: 12.3456789000e10,
! 52: 12.3456789000E-10,
! 53: .5,
! 54:
! 55: // null data
! 56: /*10*/ NULL,
! 57: null,
! 58:
! 59: // boolean data
! 60: /*12*/ true,
! 61: false,
! 62: TRUE,
! 63: FALSE,
! 64:
! 65: // empty data
! 66: /*16*/ "",
! 67: '',
! 68: array(),
! 69:
! 70: // string data
! 71: /*19*/ "string",
! 72: 'string',
! 73: $heredoc,
! 74:
! 75: // object data
! 76: /*22*/ new classA(),
! 77:
! 78: // undefined data
! 79: /*23*/ @$undefined_var,
! 80:
! 81: // unset data
! 82: /*24*/ @$unset_var,
! 83:
! 84: // resource variable
! 85: /*25*/ $fp
! 86: );
! 87:
! 88: // loop through each element of $inputs to check the behavior of array_merge()
! 89: $iterator = 1;
! 90: foreach($inputs as $input) {
! 91: echo "\n-- Iteration $iterator --\n";
! 92: var_dump( array_merge($arr1, $input) );
! 93: $iterator++;
! 94: };
! 95:
! 96: fclose($fp);
! 97:
! 98: echo "Done";
! 99: ?>
! 100: --EXPECTF--
! 101: *** Testing array_merge() : usage variations ***
! 102:
! 103: -- Iteration 1 --
! 104:
! 105: Warning: array_merge(): Argument #2 is not an array in %s on line %d
! 106: NULL
! 107:
! 108: -- Iteration 2 --
! 109:
! 110: Warning: array_merge(): Argument #2 is not an array in %s on line %d
! 111: NULL
! 112:
! 113: -- Iteration 3 --
! 114:
! 115: Warning: array_merge(): Argument #2 is not an array in %s on line %d
! 116: NULL
! 117:
! 118: -- Iteration 4 --
! 119:
! 120: Warning: array_merge(): Argument #2 is not an array in %s on line %d
! 121: NULL
! 122:
! 123: -- Iteration 5 --
! 124:
! 125: Warning: array_merge(): Argument #2 is not an array in %s on line %d
! 126: NULL
! 127:
! 128: -- Iteration 6 --
! 129:
! 130: Warning: array_merge(): Argument #2 is not an array in %s on line %d
! 131: NULL
! 132:
! 133: -- Iteration 7 --
! 134:
! 135: Warning: array_merge(): Argument #2 is not an array in %s on line %d
! 136: NULL
! 137:
! 138: -- Iteration 8 --
! 139:
! 140: Warning: array_merge(): Argument #2 is not an array in %s on line %d
! 141: NULL
! 142:
! 143: -- Iteration 9 --
! 144:
! 145: Warning: array_merge(): Argument #2 is not an array in %s on line %d
! 146: NULL
! 147:
! 148: -- Iteration 10 --
! 149:
! 150: Warning: array_merge(): Argument #2 is not an array in %s on line %d
! 151: NULL
! 152:
! 153: -- Iteration 11 --
! 154:
! 155: Warning: array_merge(): Argument #2 is not an array in %s on line %d
! 156: NULL
! 157:
! 158: -- Iteration 12 --
! 159:
! 160: Warning: array_merge(): Argument #2 is not an array in %s on line %d
! 161: NULL
! 162:
! 163: -- Iteration 13 --
! 164:
! 165: Warning: array_merge(): Argument #2 is not an array in %s on line %d
! 166: NULL
! 167:
! 168: -- Iteration 14 --
! 169:
! 170: Warning: array_merge(): Argument #2 is not an array in %s on line %d
! 171: NULL
! 172:
! 173: -- Iteration 15 --
! 174:
! 175: Warning: array_merge(): Argument #2 is not an array in %s on line %d
! 176: NULL
! 177:
! 178: -- Iteration 16 --
! 179:
! 180: Warning: array_merge(): Argument #2 is not an array in %s on line %d
! 181: NULL
! 182:
! 183: -- Iteration 17 --
! 184:
! 185: Warning: array_merge(): Argument #2 is not an array in %s on line %d
! 186: NULL
! 187:
! 188: -- Iteration 18 --
! 189: array(2) {
! 190: [0]=>
! 191: int(1)
! 192: [1]=>
! 193: int(2)
! 194: }
! 195:
! 196: -- Iteration 19 --
! 197:
! 198: Warning: array_merge(): Argument #2 is not an array in %s on line %d
! 199: NULL
! 200:
! 201: -- Iteration 20 --
! 202:
! 203: Warning: array_merge(): Argument #2 is not an array in %s on line %d
! 204: NULL
! 205:
! 206: -- Iteration 21 --
! 207:
! 208: Warning: array_merge(): Argument #2 is not an array in %s on line %d
! 209: NULL
! 210:
! 211: -- Iteration 22 --
! 212:
! 213: Warning: array_merge(): Argument #2 is not an array in %s on line %d
! 214: NULL
! 215:
! 216: -- Iteration 23 --
! 217:
! 218: Warning: array_merge(): Argument #2 is not an array in %s on line %d
! 219: NULL
! 220:
! 221: -- Iteration 24 --
! 222:
! 223: Warning: array_merge(): Argument #2 is not an array in %s on line %d
! 224: NULL
! 225:
! 226: -- Iteration 25 --
! 227:
! 228: Warning: array_merge(): Argument #2 is not an array in %s on line %d
! 229: NULL
! 230: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>