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

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

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