Annotation of embedaddon/php/ext/standard/tests/general_functions/is_array.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: Test is_array() function
! 3: --FILE--
! 4: <?php
! 5: /* Prototype: bool is_array ( mixed $var );
! 6: * Description: Finds whether the given variable is an array
! 7: */
! 8:
! 9: echo "*** Testing is_array() on different type of arrays ***\n";
! 10: /* different types of arrays */
! 11: $arrays = array(
! 12: array(),
! 13: array(NULL),
! 14: array(null),
! 15: array(true),
! 16: array(""),
! 17: array(''),
! 18: array(array(), array()),
! 19: array(array(1, 2), array('a', 'b')),
! 20: array(1 => 'One'),
! 21: array("test" => "is_array"),
! 22: array(0),
! 23: array(-1),
! 24: array(10.5, 5.6),
! 25: array("string", "test"),
! 26: array('string', 'test')
! 27: );
! 28: /* loop to check that is_array() recognizes different
! 29: type of arrays, expected output bool(true) */
! 30: $loop_counter = 1;
! 31: foreach ($arrays as $var_array ) {
! 32: echo "-- Iteration $loop_counter --\n"; $loop_counter++;
! 33: var_dump( is_array ($var_array) );
! 34: }
! 35:
! 36: echo "\n*** Testing is_array() on non array types ***\n";
! 37:
! 38: // get a resource type variable
! 39: $fp = fopen (__FILE__, "r");
! 40: $dfp = opendir ( dirname(__FILE__) );
! 41:
! 42: // unset variables
! 43: $unset_array = array(10);
! 44: unset($unset_array);
! 45:
! 46: // other types in a array
! 47: $varient_arrays = array (
! 48: /* integers */
! 49: 543915,
! 50: -5322,
! 51: 0x55F,
! 52: -0xCCF,
! 53: 123,
! 54: -0654,
! 55:
! 56: /* strings */
! 57: "",
! 58: '',
! 59: "0",
! 60: '0',
! 61: 'string',
! 62: "string",
! 63:
! 64: /* floats */
! 65: 10.0000000000000000005,
! 66: .5e6,
! 67: -.5E7,
! 68: .5E+8,
! 69: -.5e+90,
! 70: 1e5,
! 71:
! 72: /* objects */
! 73: new stdclass,
! 74:
! 75: /* resources */
! 76: $fp,
! 77: $dfp,
! 78:
! 79: /* nulls */
! 80: null,
! 81: NULL,
! 82:
! 83: /* boolean */
! 84: true,
! 85: TRUE,
! 86: FALSE,
! 87: false,
! 88:
! 89: /* unset/undefined arrays */
! 90: @$unset_array,
! 91: @$undefined_array
! 92: );
! 93: /* loop through the $varient_array to see working of
! 94: is_array() on non array types, expected output bool(false) */
! 95: $loop_counter = 1;
! 96: foreach ($varient_arrays as $type ) {
! 97: echo "-- Iteration $loop_counter --\n"; $loop_counter++;
! 98: var_dump( is_array ($type) );
! 99: }
! 100:
! 101: echo "\n*** Testing error conditions ***\n";
! 102: //Zero argument
! 103: var_dump( is_array() );
! 104:
! 105: //arguments more than expected
! 106: var_dump( is_array ($fp, $fp) );
! 107:
! 108: echo "Done\n";
! 109: /* close resources */
! 110: fclose($fp);
! 111: closedir($dfp);
! 112: ?>
! 113: --EXPECTF--
! 114: *** Testing is_array() on different type of arrays ***
! 115: -- Iteration 1 --
! 116: bool(true)
! 117: -- Iteration 2 --
! 118: bool(true)
! 119: -- Iteration 3 --
! 120: bool(true)
! 121: -- Iteration 4 --
! 122: bool(true)
! 123: -- Iteration 5 --
! 124: bool(true)
! 125: -- Iteration 6 --
! 126: bool(true)
! 127: -- Iteration 7 --
! 128: bool(true)
! 129: -- Iteration 8 --
! 130: bool(true)
! 131: -- Iteration 9 --
! 132: bool(true)
! 133: -- Iteration 10 --
! 134: bool(true)
! 135: -- Iteration 11 --
! 136: bool(true)
! 137: -- Iteration 12 --
! 138: bool(true)
! 139: -- Iteration 13 --
! 140: bool(true)
! 141: -- Iteration 14 --
! 142: bool(true)
! 143: -- Iteration 15 --
! 144: bool(true)
! 145:
! 146: *** Testing is_array() on non array types ***
! 147: -- Iteration 1 --
! 148: bool(false)
! 149: -- Iteration 2 --
! 150: bool(false)
! 151: -- Iteration 3 --
! 152: bool(false)
! 153: -- Iteration 4 --
! 154: bool(false)
! 155: -- Iteration 5 --
! 156: bool(false)
! 157: -- Iteration 6 --
! 158: bool(false)
! 159: -- Iteration 7 --
! 160: bool(false)
! 161: -- Iteration 8 --
! 162: bool(false)
! 163: -- Iteration 9 --
! 164: bool(false)
! 165: -- Iteration 10 --
! 166: bool(false)
! 167: -- Iteration 11 --
! 168: bool(false)
! 169: -- Iteration 12 --
! 170: bool(false)
! 171: -- Iteration 13 --
! 172: bool(false)
! 173: -- Iteration 14 --
! 174: bool(false)
! 175: -- Iteration 15 --
! 176: bool(false)
! 177: -- Iteration 16 --
! 178: bool(false)
! 179: -- Iteration 17 --
! 180: bool(false)
! 181: -- Iteration 18 --
! 182: bool(false)
! 183: -- Iteration 19 --
! 184: bool(false)
! 185: -- Iteration 20 --
! 186: bool(false)
! 187: -- Iteration 21 --
! 188: bool(false)
! 189: -- Iteration 22 --
! 190: bool(false)
! 191: -- Iteration 23 --
! 192: bool(false)
! 193: -- Iteration 24 --
! 194: bool(false)
! 195: -- Iteration 25 --
! 196: bool(false)
! 197: -- Iteration 26 --
! 198: bool(false)
! 199: -- Iteration 27 --
! 200: bool(false)
! 201: -- Iteration 28 --
! 202: bool(false)
! 203: -- Iteration 29 --
! 204: bool(false)
! 205:
! 206: *** Testing error conditions ***
! 207:
! 208: Warning: is_array() expects exactly 1 parameter, 0 given in %s on line %d
! 209: bool(false)
! 210:
! 211: Warning: is_array() expects exactly 1 parameter, 2 given in %s on line %d
! 212: bool(false)
! 213: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>