Annotation of embedaddon/php/ext/standard/tests/array/array_fill_variation1.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: Test array_fill() function : usage variations  - unexpected values for 'start_key' argument
                      3: --SKIPIF--
                      4: <?php
                      5: if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only");
                      6: ?>
                      7: --FILE--
                      8: <?php
                      9: /* Prototype  : proto array array_fill(int start_key, int num, mixed val)
                     10:  * Description: Create an array containing num elements starting with index start_key each initialized to val 
                     11:  * Source code: ext/standard/array.c
                     12:  */
                     13: 
                     14: /*
                     15:  * testing array_fill() by passing different unexpected value for 'start_key' argument
                     16:  */
                     17: 
                     18: echo "*** Testing array_fill() : usage variations ***\n";
                     19: 
                     20: // Initialise function arguments not being substituted 
                     21: $num = 2;
                     22: $val = 100;
                     23: 
                     24: //get an unset variable
                     25: $unset_var = 10;
                     26: unset ($unset_var);
                     27: 
                     28: //get a resource variable
                     29: $fp = fopen(__FILE__, "r");
                     30: 
                     31: //define a class
                     32: class test
                     33: {
                     34:   var $t = 10;
                     35:   function __toString()
                     36:   {
                     37:     return "testObject";
                     38:   }
                     39: }
                     40: 
                     41: 
                     42: //array of different values for 'start_key' argument
                     43: $values = array(
                     44: 
                     45:             // float values
                     46:   /* 1  */  10.5,
                     47:             -10.5,
                     48:             12.3456789000e10,
                     49:             12.34567890006E-10,
                     50:             .5,
                     51: 
                     52:             // array values
                     53:   /* 6  */  array(),
                     54:             array(0),
                     55:             array(1),
                     56:             array(1, 2),
                     57:             array('color' => 'red', 'item' => 'pen'),
                     58: 
                     59:             // null values
                     60:   /* 11 */  NULL,
                     61:             null,
                     62: 
                     63:             // boolean values 
                     64:   /* 13 */  true,
                     65:             false,
                     66:             TRUE,
                     67:             FALSE,
                     68: 
                     69:             // empty string 
                     70:   /* 17 */  "",
                     71:             '',
                     72: 
                     73:             // string values
                     74:   /* 19 */  "string",
                     75:             'string',
                     76: 
                     77:             // objects
                     78:   /* 21 */  new test(),
                     79: 
                     80:             // undefined  variable
                     81:             @$undefined_var,
                     82: 
                     83:             // unset variable 
                     84:             @$unset_var,
                     85: 
                     86:             // resource variable
                     87:   /* 24 */  $fp
                     88: );
                     89: 
                     90: // loop through each element of the array for start_key 
                     91: // check the working of array_fill()
                     92: echo "--- Testing array_fill() with different values for 'start_key' arg ---\n";
                     93: $counter = 1;
                     94: for($index = 0; $index < count($values); $index ++)
                     95: {
                     96:   echo "-- Iteration $counter --\n";
                     97:   $start_key = $values[$index];
                     98:  
                     99:   var_dump( array_fill($start_key,$num,$val) );
                    100:  
                    101:   $counter ++;
                    102: }
                    103: 
                    104: // close the resource used
                    105: fclose($fp);
                    106: 
                    107: echo "Done";
                    108: ?>
                    109: --EXPECTF--
                    110: *** Testing array_fill() : usage variations ***
                    111: --- Testing array_fill() with different values for 'start_key' arg ---
                    112: -- Iteration 1 --
                    113: array(2) {
                    114:   [10]=>
                    115:   int(100)
                    116:   [11]=>
                    117:   int(100)
                    118: }
                    119: -- Iteration 2 --
                    120: array(2) {
                    121:   [-10]=>
                    122:   int(100)
                    123:   [0]=>
                    124:   int(100)
                    125: }
                    126: -- Iteration 3 --
                    127: array(2) {
                    128:   [-1097262584]=>
                    129:   int(100)
                    130:   [0]=>
                    131:   int(100)
                    132: }
                    133: -- Iteration 4 --
                    134: array(2) {
                    135:   [0]=>
                    136:   int(100)
                    137:   [1]=>
                    138:   int(100)
                    139: }
                    140: -- Iteration 5 --
                    141: array(2) {
                    142:   [0]=>
                    143:   int(100)
                    144:   [1]=>
                    145:   int(100)
                    146: }
                    147: -- Iteration 6 --
                    148: 
                    149: Warning: array_fill() expects parameter 1 to be long, array given in %sarray_fill_variation1.php on line %d
                    150: NULL
                    151: -- Iteration 7 --
                    152: 
                    153: Warning: array_fill() expects parameter 1 to be long, array given in %sarray_fill_variation1.php on line %d
                    154: NULL
                    155: -- Iteration 8 --
                    156: 
                    157: Warning: array_fill() expects parameter 1 to be long, array given in %sarray_fill_variation1.php on line %d
                    158: NULL
                    159: -- Iteration 9 --
                    160: 
                    161: Warning: array_fill() expects parameter 1 to be long, array given in %sarray_fill_variation1.php on line %d
                    162: NULL
                    163: -- Iteration 10 --
                    164: 
                    165: Warning: array_fill() expects parameter 1 to be long, array given in %sarray_fill_variation1.php on line %d
                    166: NULL
                    167: -- Iteration 11 --
                    168: array(2) {
                    169:   [0]=>
                    170:   int(100)
                    171:   [1]=>
                    172:   int(100)
                    173: }
                    174: -- Iteration 12 --
                    175: array(2) {
                    176:   [0]=>
                    177:   int(100)
                    178:   [1]=>
                    179:   int(100)
                    180: }
                    181: -- Iteration 13 --
                    182: array(2) {
                    183:   [1]=>
                    184:   int(100)
                    185:   [2]=>
                    186:   int(100)
                    187: }
                    188: -- Iteration 14 --
                    189: array(2) {
                    190:   [0]=>
                    191:   int(100)
                    192:   [1]=>
                    193:   int(100)
                    194: }
                    195: -- Iteration 15 --
                    196: array(2) {
                    197:   [1]=>
                    198:   int(100)
                    199:   [2]=>
                    200:   int(100)
                    201: }
                    202: -- Iteration 16 --
                    203: array(2) {
                    204:   [0]=>
                    205:   int(100)
                    206:   [1]=>
                    207:   int(100)
                    208: }
                    209: -- Iteration 17 --
                    210: 
                    211: Warning: array_fill() expects parameter 1 to be long, string given in %sarray_fill_variation1.php on line %d
                    212: NULL
                    213: -- Iteration 18 --
                    214: 
                    215: Warning: array_fill() expects parameter 1 to be long, string given in %sarray_fill_variation1.php on line %d
                    216: NULL
                    217: -- Iteration 19 --
                    218: 
                    219: Warning: array_fill() expects parameter 1 to be long, string given in %sarray_fill_variation1.php on line %d
                    220: NULL
                    221: -- Iteration 20 --
                    222: 
                    223: Warning: array_fill() expects parameter 1 to be long, string given in %sarray_fill_variation1.php on line %d
                    224: NULL
                    225: -- Iteration 21 --
                    226: 
                    227: Warning: array_fill() expects parameter 1 to be long, object given in %sarray_fill_variation1.php on line %d
                    228: NULL
                    229: -- Iteration 22 --
                    230: array(2) {
                    231:   [0]=>
                    232:   int(100)
                    233:   [1]=>
                    234:   int(100)
                    235: }
                    236: -- Iteration 23 --
                    237: array(2) {
                    238:   [0]=>
                    239:   int(100)
                    240:   [1]=>
                    241:   int(100)
                    242: }
                    243: -- Iteration 24 --
                    244: 
                    245: Warning: array_fill() expects parameter 1 to be long, resource given in %sarray_fill_variation1.php on line %d
                    246: NULL
                    247: Done

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>