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