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

1.1       misho       1: --TEST--
                      2: Test array_chunk() function : usage variations - unexpected values for 'size' argument 
                      3: --FILE--
                      4: <?php
                      5: /* Prototype  : array array_chunk(array $array, int $size [, bool $preserve_keys])
                      6:  * Description: Split array into chunks 
                      7:               : Chunks an array into size  large chunks
                      8:  * Source code: ext/standard/array.c
                      9: */
                     10: 
                     11: /*
                     12: * Testing array_chunk() function with unexpected values for 'size' argument 
                     13: */
                     14: 
                     15: echo "*** Testing array_chunk() : usage variations ***\n";
                     16: 
                     17: // input array
                     18: $input = array(1, 2);
                     19: 
                     20: //get an unset variable
                     21: $unset_var = 10;
                     22: unset ($unset_var);
                     23: 
                     24: //array of values to iterate over
                     25: $values = array (
                     26: 
                     27:         // float data
                     28: /*1*/   10.5,
                     29:         -10.5,
                     30:         10.5e10,
                     31:         10.6E-10,
                     32:         .5,
                     33: 
                     34:         // array data
                     35: /*6*/   array(),
                     36:         array(0),
                     37:         array(1),
                     38:         array(1, 2),
                     39:         array('color' => 'red', 'item' => 'pen'),
                     40: 
                     41:         // null data
                     42: /*11*/  NULL,
                     43:         null,
                     44: 
                     45:         // boolean data
                     46: /*13*/  true,
                     47:         false,
                     48:         TRUE,
                     49:         FALSE,
                     50: 
                     51:         // empty data
                     52: /*17*/  "",
                     53:         '',
                     54: 
                     55:         // string data
                     56: /*19*/  "string",
                     57:         'string',
                     58: 
                     59:         // object data
                     60: /*21*/  new stdclass(),
                     61: 
                     62:         // undefined data
                     63: /*22*/  @undefined_var,
                     64: 
                     65:         // unset data
                     66: /*23*/  @unset_var
                     67: 
                     68: );
                     69: 
                     70: // loop through each element of the array for size
                     71: $count = 1;
                     72: foreach($values as $value){
                     73:   echo "\n-- Iteration $count --\n";
                     74:   var_dump( array_chunk($input, $value) );
                     75:   var_dump( array_chunk($input, $value, true) );
                     76:   var_dump( array_chunk($input, $value, false) );
                     77:   $count++;
                     78: }
                     79: 
                     80: echo "Done";
                     81: ?>
                     82: --EXPECTF--
                     83: *** Testing array_chunk() : usage variations ***
                     84: 
                     85: -- Iteration 1 --
                     86: array(1) {
                     87:   [0]=>
                     88:   array(2) {
                     89:     [0]=>
                     90:     int(1)
                     91:     [1]=>
                     92:     int(2)
                     93:   }
                     94: }
                     95: array(1) {
                     96:   [0]=>
                     97:   array(2) {
                     98:     [0]=>
                     99:     int(1)
                    100:     [1]=>
                    101:     int(2)
                    102:   }
                    103: }
                    104: array(1) {
                    105:   [0]=>
                    106:   array(2) {
                    107:     [0]=>
                    108:     int(1)
                    109:     [1]=>
                    110:     int(2)
                    111:   }
                    112: }
                    113: 
                    114: -- Iteration 2 --
                    115: 
                    116: Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
                    117: NULL
                    118: 
                    119: Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
                    120: NULL
                    121: 
                    122: Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
                    123: NULL
                    124: 
                    125: -- Iteration 3 --
                    126: array(1) {
                    127:   [0]=>
                    128:   array(2) {
                    129:     [0]=>
                    130:     int(1)
                    131:     [1]=>
                    132:     int(2)
                    133:   }
                    134: }
                    135: array(1) {
                    136:   [0]=>
                    137:   array(2) {
                    138:     [0]=>
                    139:     int(1)
                    140:     [1]=>
                    141:     int(2)
                    142:   }
                    143: }
                    144: array(1) {
                    145:   [0]=>
                    146:   array(2) {
                    147:     [0]=>
                    148:     int(1)
                    149:     [1]=>
                    150:     int(2)
                    151:   }
                    152: }
                    153: 
                    154: -- Iteration 4 --
                    155: 
                    156: Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
                    157: NULL
                    158: 
                    159: Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
                    160: NULL
                    161: 
                    162: Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
                    163: NULL
                    164: 
                    165: -- Iteration 5 --
                    166: 
                    167: Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
                    168: NULL
                    169: 
                    170: Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
                    171: NULL
                    172: 
                    173: Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
                    174: NULL
                    175: 
                    176: -- Iteration 6 --
                    177: 
                    178: Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d
                    179: NULL
                    180: 
                    181: Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d
                    182: NULL
                    183: 
                    184: Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d
                    185: NULL
                    186: 
                    187: -- Iteration 7 --
                    188: 
                    189: Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d
                    190: NULL
                    191: 
                    192: Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d
                    193: NULL
                    194: 
                    195: Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d
                    196: NULL
                    197: 
                    198: -- Iteration 8 --
                    199: 
                    200: Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d
                    201: NULL
                    202: 
                    203: Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d
                    204: NULL
                    205: 
                    206: Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d
                    207: NULL
                    208: 
                    209: -- Iteration 9 --
                    210: 
                    211: Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d
                    212: NULL
                    213: 
                    214: Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d
                    215: NULL
                    216: 
                    217: Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d
                    218: NULL
                    219: 
                    220: -- Iteration 10 --
                    221: 
                    222: Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d
                    223: NULL
                    224: 
                    225: Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d
                    226: NULL
                    227: 
                    228: Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d
                    229: NULL
                    230: 
                    231: -- Iteration 11 --
                    232: 
                    233: Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
                    234: NULL
                    235: 
                    236: Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
                    237: NULL
                    238: 
                    239: Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
                    240: NULL
                    241: 
                    242: -- Iteration 12 --
                    243: 
                    244: Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
                    245: NULL
                    246: 
                    247: Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
                    248: NULL
                    249: 
                    250: Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
                    251: NULL
                    252: 
                    253: -- Iteration 13 --
                    254: array(2) {
                    255:   [0]=>
                    256:   array(1) {
                    257:     [0]=>
                    258:     int(1)
                    259:   }
                    260:   [1]=>
                    261:   array(1) {
                    262:     [0]=>
                    263:     int(2)
                    264:   }
                    265: }
                    266: array(2) {
                    267:   [0]=>
                    268:   array(1) {
                    269:     [0]=>
                    270:     int(1)
                    271:   }
                    272:   [1]=>
                    273:   array(1) {
                    274:     [1]=>
                    275:     int(2)
                    276:   }
                    277: }
                    278: array(2) {
                    279:   [0]=>
                    280:   array(1) {
                    281:     [0]=>
                    282:     int(1)
                    283:   }
                    284:   [1]=>
                    285:   array(1) {
                    286:     [0]=>
                    287:     int(2)
                    288:   }
                    289: }
                    290: 
                    291: -- Iteration 14 --
                    292: 
                    293: Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
                    294: NULL
                    295: 
                    296: Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
                    297: NULL
                    298: 
                    299: Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
                    300: NULL
                    301: 
                    302: -- Iteration 15 --
                    303: array(2) {
                    304:   [0]=>
                    305:   array(1) {
                    306:     [0]=>
                    307:     int(1)
                    308:   }
                    309:   [1]=>
                    310:   array(1) {
                    311:     [0]=>
                    312:     int(2)
                    313:   }
                    314: }
                    315: array(2) {
                    316:   [0]=>
                    317:   array(1) {
                    318:     [0]=>
                    319:     int(1)
                    320:   }
                    321:   [1]=>
                    322:   array(1) {
                    323:     [1]=>
                    324:     int(2)
                    325:   }
                    326: }
                    327: array(2) {
                    328:   [0]=>
                    329:   array(1) {
                    330:     [0]=>
                    331:     int(1)
                    332:   }
                    333:   [1]=>
                    334:   array(1) {
                    335:     [0]=>
                    336:     int(2)
                    337:   }
                    338: }
                    339: 
                    340: -- Iteration 16 --
                    341: 
                    342: Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
                    343: NULL
                    344: 
                    345: Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
                    346: NULL
                    347: 
                    348: Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
                    349: NULL
                    350: 
                    351: -- Iteration 17 --
                    352: 
                    353: Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d
                    354: NULL
                    355: 
                    356: Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d
                    357: NULL
                    358: 
                    359: Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d
                    360: NULL
                    361: 
                    362: -- Iteration 18 --
                    363: 
                    364: Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d
                    365: NULL
                    366: 
                    367: Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d
                    368: NULL
                    369: 
                    370: Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d
                    371: NULL
                    372: 
                    373: -- Iteration 19 --
                    374: 
                    375: Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d
                    376: NULL
                    377: 
                    378: Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d
                    379: NULL
                    380: 
                    381: Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d
                    382: NULL
                    383: 
                    384: -- Iteration 20 --
                    385: 
                    386: Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d
                    387: NULL
                    388: 
                    389: Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d
                    390: NULL
                    391: 
                    392: Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d
                    393: NULL
                    394: 
                    395: -- Iteration 21 --
                    396: 
                    397: Warning: array_chunk() expects parameter 2 to be long, object given in %s on line %d
                    398: NULL
                    399: 
                    400: Warning: array_chunk() expects parameter 2 to be long, object given in %s on line %d
                    401: NULL
                    402: 
                    403: Warning: array_chunk() expects parameter 2 to be long, object given in %s on line %d
                    404: NULL
                    405: 
                    406: -- Iteration 22 --
                    407: 
                    408: Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d
                    409: NULL
                    410: 
                    411: Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d
                    412: NULL
                    413: 
                    414: Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d
                    415: NULL
                    416: 
                    417: -- Iteration 23 --
                    418: 
                    419: Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d
                    420: NULL
                    421: 
                    422: Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d
                    423: NULL
                    424: 
                    425: Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d
                    426: NULL
                    427: Done

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