Return to sizeof_variation5.phpt CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / ext / standard / tests / array |
1.1 misho 1: --TEST-- 2: Test sizeof() function : usage variations - different values for 'mode' argument 3: --FILE-- 4: <?php 5: /* Prototype : int sizeof($mixed var[, int $mode]) 6: * Description: Counts an elements in an array. If Standard PHP library is installed, 7: * it will return the properties of an object. 8: * Source code: ext/standard/basic_functions.c 9: * Alias to functions: count() 10: */ 11: 12: echo "*** Testing sizeof() : usage variations ***\n"; 13: 14: echo "--- Testing sizeof() with different values for 'mode' argument ---\n"; 15: $array1 = array(1, 2, 3, 4, array(1.0, 2.0, array()), array() ); 16: 17: // get a resource variable 18: $fp = fopen(__FILE__, "r"); 19: 20: //unset variable 21: $unset_var = 10; 22: unset($unset_var); 23: 24: //class declaration 25: class test 26: { 27: public $member1; 28: } 29: 30: $mode_values = array ( 31: /* 1 */ COUNT_NORMAL, 32: COUNT_RECURSIVE, 33: 0, // same as COUNT_NORMAL 34: 1, // same as COUNT_RECURSIVE 35: 36: /* 5 */ TRUE, // same as COUNT_RECURSIVE 37: true, // same as COUNT_RECURSIVE 38: FALSE, // same as COUNT_NORMAL 39: false, // same as COUNT_NORMAL 40: NULL, // same as COUNT_NORMAL 41: /* 10 */ null, // same as COUNT_NORMAL 42: 100, 43: 10.5, 44: 12.34e3, 45: 12.34E-2, 46: /* 15 */ .5, 47: "", 48: '', 49: "string", 50: 'string', 51: /* 20 */ @$unset_var, 52: new test(), 53: /* 22 */ $fp 54: ); 55: 56: // loop through the each element of $modes_array for 'mode' argument 57: // and check the working of sizeof() 58: $counter = 1; 59: for($i = 0; $i < count($mode_values); $i++) 60: { 61: echo "-- Iteration $counter --\n"; 62: $mode = $mode_values[$i]; 63: 64: var_dump( sizeof($array1, $mode) ); 65: 66: $counter++; 67: } 68: 69: fclose($fp); 70: 71: echo "Done"; 72: ?> 73: --EXPECTF-- 74: *** Testing sizeof() : usage variations *** 75: --- Testing sizeof() with different values for 'mode' argument --- 76: -- Iteration 1 -- 77: int(6) 78: -- Iteration 2 -- 79: int(9) 80: -- Iteration 3 -- 81: int(6) 82: -- Iteration 4 -- 83: int(9) 84: -- Iteration 5 -- 85: int(9) 86: -- Iteration 6 -- 87: int(9) 88: -- Iteration 7 -- 89: int(6) 90: -- Iteration 8 -- 91: int(6) 92: -- Iteration 9 -- 93: int(6) 94: -- Iteration 10 -- 95: int(6) 96: -- Iteration 11 -- 97: int(6) 98: -- Iteration 12 -- 99: int(6) 100: -- Iteration 13 -- 101: int(6) 102: -- Iteration 14 -- 103: int(6) 104: -- Iteration 15 -- 105: int(6) 106: -- Iteration 16 -- 107: 108: Warning: sizeof() expects parameter 2 to be long, string given in %s on line %d 109: NULL 110: -- Iteration 17 -- 111: 112: Warning: sizeof() expects parameter 2 to be long, string given in %s on line %d 113: NULL 114: -- Iteration 18 -- 115: 116: Warning: sizeof() expects parameter 2 to be long, string given in %s on line %d 117: NULL 118: -- Iteration 19 -- 119: 120: Warning: sizeof() expects parameter 2 to be long, string given in %s on line %d 121: NULL 122: -- Iteration 20 -- 123: int(6) 124: -- Iteration 21 -- 125: 126: Warning: sizeof() expects parameter 2 to be long, object given in %s on line %d 127: NULL 128: -- Iteration 22 -- 129: 130: Warning: sizeof() expects parameter 2 to be long, resource given in %s on line %d 131: NULL 132: Done