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