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

1.1       misho       1: --TEST--
                      2: Test array_slice() function : usage variations - Pass different data types as $length arg
                      3: --SKIPIF--
                      4: <?php if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only"); ?>
                      5: --FILE--
                      6: <?php
                      7: /* Prototype  : array array_slice(array $input, int $offset [, int $length [, bool $preserve_keys]])
                      8:  * Description: Returns elements specified by offset and length 
                      9:  * Source code: ext/standard/array.c
                     10:  */
                     11: 
                     12: /*
                     13:  * Pass different data types as $length argument to array_slice to test behaviour
                     14:  */
                     15: 
                     16: echo "*** Testing array_slice() : usage variations ***\n";
                     17: 
                     18: // Initialise function arguments not being substituted
                     19: $input_array = array('one' => 1, 2, 'three' => 3, 4);
                     20: $offset = 2;
                     21: 
                     22: //get an unset variable
                     23: $unset_var = 10;
                     24: unset ($unset_var);
                     25: 
                     26: // heredoc string
                     27: $heredoc = <<<EOT
                     28: hello world
                     29: EOT;
                     30: 
                     31: // unexpected values to be passed to $length argument
                     32: $inputs = array(
                     33: 
                     34:        // int data
                     35: /*1*/  0,
                     36:        1,
                     37:        12345,
                     38:        -2345,
                     39: 
                     40:        // float data
                     41: /*5*/  10.5,
                     42:        -10.5,
                     43:        12.3456789000e10,
                     44:        12.3456789000E-10,
                     45:        .5,
                     46: 
                     47:        // null data
                     48: /*10*/ NULL,
                     49:        null,
                     50: 
                     51:        // boolean data
                     52: /*12*/ true,
                     53:        false,
                     54:        TRUE,
                     55:        FALSE,
                     56:        
                     57:        // empty data
                     58: /*16*/ "",
                     59:        '',
                     60:        array(),
                     61: 
                     62:        // string data
                     63: /*19*/ "string",
                     64:        'string',
                     65:        $heredoc,
                     66: 
                     67:        // undefined data
                     68: /*22*/ @$undefined_var,
                     69: 
                     70:        // unset data
                     71: /*23*/ @$unset_var,
                     72: );
                     73: 
                     74: // loop through each element of $inputs to check the behavior of array_slice
                     75: $iterator = 1;
                     76: foreach($inputs as $input) {
                     77:   echo "\n-- Iteration $iterator --\n";
                     78:   var_dump( array_slice($input_array, $offset, $input) );
                     79:   $iterator++;
                     80: };
                     81: 
                     82: echo "Done";
                     83: ?>
                     84: 
                     85: --EXPECTF--
                     86: *** Testing array_slice() : usage variations ***
                     87: 
                     88: -- Iteration 1 --
                     89: array(0) {
                     90: }
                     91: 
                     92: -- Iteration 2 --
                     93: array(1) {
                     94:   ["three"]=>
                     95:   int(3)
                     96: }
                     97: 
                     98: -- Iteration 3 --
                     99: array(2) {
                    100:   ["three"]=>
                    101:   int(3)
                    102:   [0]=>
                    103:   int(4)
                    104: }
                    105: 
                    106: -- Iteration 4 --
                    107: array(0) {
                    108: }
                    109: 
                    110: -- Iteration 5 --
                    111: array(2) {
                    112:   ["three"]=>
                    113:   int(3)
                    114:   [0]=>
                    115:   int(4)
                    116: }
                    117: 
                    118: -- Iteration 6 --
                    119: array(0) {
                    120: }
                    121: 
                    122: -- Iteration 7 --
                    123: array(2) {
                    124:   ["three"]=>
                    125:   int(3)
                    126:   [0]=>
                    127:   int(4)
                    128: }
                    129: 
                    130: -- Iteration 8 --
                    131: array(0) {
                    132: }
                    133: 
                    134: -- Iteration 9 --
                    135: array(0) {
                    136: }
                    137: 
                    138: -- Iteration 10 --
                    139: array(2) {
                    140:   ["three"]=>
                    141:   int(3)
                    142:   [0]=>
                    143:   int(4)
                    144: }
                    145: 
                    146: -- Iteration 11 --
                    147: array(2) {
                    148:   ["three"]=>
                    149:   int(3)
                    150:   [0]=>
                    151:   int(4)
                    152: }
                    153: 
                    154: -- Iteration 12 --
                    155: array(1) {
                    156:   ["three"]=>
                    157:   int(3)
                    158: }
                    159: 
                    160: -- Iteration 13 --
                    161: array(0) {
                    162: }
                    163: 
                    164: -- Iteration 14 --
                    165: array(1) {
                    166:   ["three"]=>
                    167:   int(3)
                    168: }
                    169: 
                    170: -- Iteration 15 --
                    171: array(0) {
                    172: }
                    173: 
                    174: -- Iteration 16 --
                    175: array(0) {
                    176: }
                    177: 
                    178: -- Iteration 17 --
                    179: array(0) {
                    180: }
                    181: 
                    182: -- Iteration 18 --
                    183: array(0) {
                    184: }
                    185: 
                    186: -- Iteration 19 --
                    187: array(0) {
                    188: }
                    189: 
                    190: -- Iteration 20 --
                    191: array(0) {
                    192: }
                    193: 
                    194: -- Iteration 21 --
                    195: array(0) {
                    196: }
                    197: 
                    198: -- Iteration 22 --
                    199: array(2) {
                    200:   ["three"]=>
                    201:   int(3)
                    202:   [0]=>
                    203:   int(4)
                    204: }
                    205: 
                    206: -- Iteration 23 --
                    207: array(2) {
                    208:   ["three"]=>
                    209:   int(3)
                    210:   [0]=>
                    211:   int(4)
                    212: }
                    213: Done

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