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

1.1       misho       1: --TEST--
                      2: Test array_reverse() function : usage variations - assoc. array with diff. keys for 'array' argument
                      3: --FILE--
                      4: <?php
                      5: /* Prototype  : array array_reverse(array $array [, bool $preserve_keys])
                      6:  * Description: Return input as a new array with the order of the entries reversed
                      7:  * Source code: ext/standard/array.c
                      8: */
                      9: 
                     10: /*
                     11:  * Testing the functionality of array_reverse() by giving associative arrays with different
                     12:  * keys for $array argument
                     13: */
                     14: 
                     15: echo "*** Testing array_reverse() : usage variations ***\n";
                     16: 
                     17: //get an unset variable
                     18: $unset_var = 10;
                     19: unset ($unset_var);
                     20: 
                     21: //get a resource variable
                     22: $fp = fopen(__FILE__, "r");
                     23: 
                     24: //get a class
                     25: class classA{
                     26:   public function __toString(){
                     27:     return "Class A object";
                     28:   }
                     29: }
                     30: 
                     31: // get a heredoc string
                     32: $heredoc = <<<EOT
                     33: Hello world
                     34: EOT;
                     35: 
                     36: // initializing the array
                     37: $arrays = array (
                     38: 
                     39:        // empty array
                     40: /*1*/  array(),
                     41: 
                     42:        // arrays with integer keys
                     43:        array(0 => "0"),
                     44:        array(1 => "1"),
                     45:        array(1 => "1", 2 => "2", 3 => "3", 4 => "4"),
                     46:  
                     47:        // arrays with float keys
                     48: /*5*/  array(2.3333 => "float"),
                     49:        array(1.2 => "f1", 3.33 => "f2", 4.89999922839999 => "f3", 33333333.333333 => "f4"),
                     50:   
                     51:        // arrays with string keys
                     52:        array("\tHello" => 111, "re\td" => "color", "\v\fworld" => 2.2, "pen\n" => 33),
                     53: /*8*/  array("\tHello" => 111, "re\td" => "color", "\v\fworld" => 2.2, "pen\n" => 33),
                     54:        array("hello", $heredoc => "string"), // heredoc
                     55: 
                     56:        // array with object, unset variable and resource variable
                     57:        array(new classA() => 11, @$unset_var => "hello", $fp => 'resource'), 
                     58: 
                     59:        // array with mixed values
                     60: /*11*/ array('hello' => 1, new classA() => 2, "fruit" => 2.2, $fp => 'resource', 133 => "int", 444.432 => "float", @$unset_var => "unset", $heredoc => "heredoc")
                     61: );
                     62: 
                     63: // loop through the various elements of $arrays to test array_reverse()
                     64: $iterator = 1;
                     65: foreach($arrays as $array) {
                     66:   echo "-- Iteration $iterator --\n";
                     67:   // with default argument
                     68:   echo "- default argument -\n";
                     69:   var_dump( array_reverse($array) );
                     70:   // with $preserve_keys argument
                     71:   echo "- \$preserve keys = true -\n";
                     72:   var_dump( array_reverse($array, true) );
                     73:   echo "- \$preserve_keys = false -\n";
                     74:   var_dump( array_reverse($array, false) );
                     75:   $iterator++;
                     76: };
                     77: 
                     78: // close the file resource used
                     79: fclose($fp);
                     80: 
                     81: echo "Done";
                     82: ?>
                     83: --EXPECTF--
                     84: *** Testing array_reverse() : usage variations ***
                     85: 
                     86: Warning: Illegal offset type in %s on line %d
                     87: 
                     88: Warning: Illegal offset type in %s on line %d
                     89: 
                     90: Warning: Illegal offset type in %s on line %d
                     91: 
                     92: Warning: Illegal offset type in %s on line %d
                     93: -- Iteration 1 --
                     94: - default argument -
                     95: array(0) {
                     96: }
                     97: - $preserve keys = true -
                     98: array(0) {
                     99: }
                    100: - $preserve_keys = false -
                    101: array(0) {
                    102: }
                    103: -- Iteration 2 --
                    104: - default argument -
                    105: array(1) {
                    106:   [0]=>
                    107:   string(1) "0"
                    108: }
                    109: - $preserve keys = true -
                    110: array(1) {
                    111:   [0]=>
                    112:   string(1) "0"
                    113: }
                    114: - $preserve_keys = false -
                    115: array(1) {
                    116:   [0]=>
                    117:   string(1) "0"
                    118: }
                    119: -- Iteration 3 --
                    120: - default argument -
                    121: array(1) {
                    122:   [0]=>
                    123:   string(1) "1"
                    124: }
                    125: - $preserve keys = true -
                    126: array(1) {
                    127:   [1]=>
                    128:   string(1) "1"
                    129: }
                    130: - $preserve_keys = false -
                    131: array(1) {
                    132:   [0]=>
                    133:   string(1) "1"
                    134: }
                    135: -- Iteration 4 --
                    136: - default argument -
                    137: array(4) {
                    138:   [0]=>
                    139:   string(1) "4"
                    140:   [1]=>
                    141:   string(1) "3"
                    142:   [2]=>
                    143:   string(1) "2"
                    144:   [3]=>
                    145:   string(1) "1"
                    146: }
                    147: - $preserve keys = true -
                    148: array(4) {
                    149:   [4]=>
                    150:   string(1) "4"
                    151:   [3]=>
                    152:   string(1) "3"
                    153:   [2]=>
                    154:   string(1) "2"
                    155:   [1]=>
                    156:   string(1) "1"
                    157: }
                    158: - $preserve_keys = false -
                    159: array(4) {
                    160:   [0]=>
                    161:   string(1) "4"
                    162:   [1]=>
                    163:   string(1) "3"
                    164:   [2]=>
                    165:   string(1) "2"
                    166:   [3]=>
                    167:   string(1) "1"
                    168: }
                    169: -- Iteration 5 --
                    170: - default argument -
                    171: array(1) {
                    172:   [0]=>
                    173:   string(5) "float"
                    174: }
                    175: - $preserve keys = true -
                    176: array(1) {
                    177:   [2]=>
                    178:   string(5) "float"
                    179: }
                    180: - $preserve_keys = false -
                    181: array(1) {
                    182:   [0]=>
                    183:   string(5) "float"
                    184: }
                    185: -- Iteration 6 --
                    186: - default argument -
                    187: array(4) {
                    188:   [0]=>
                    189:   string(2) "f4"
                    190:   [1]=>
                    191:   string(2) "f3"
                    192:   [2]=>
                    193:   string(2) "f2"
                    194:   [3]=>
                    195:   string(2) "f1"
                    196: }
                    197: - $preserve keys = true -
                    198: array(4) {
                    199:   [33333333]=>
                    200:   string(2) "f4"
                    201:   [4]=>
                    202:   string(2) "f3"
                    203:   [3]=>
                    204:   string(2) "f2"
                    205:   [1]=>
                    206:   string(2) "f1"
                    207: }
                    208: - $preserve_keys = false -
                    209: array(4) {
                    210:   [0]=>
                    211:   string(2) "f4"
                    212:   [1]=>
                    213:   string(2) "f3"
                    214:   [2]=>
                    215:   string(2) "f2"
                    216:   [3]=>
                    217:   string(2) "f1"
                    218: }
                    219: -- Iteration 7 --
                    220: - default argument -
                    221: array(4) {
                    222:   ["pen
                    223: "]=>
                    224:   int(33)
                    225:   ["world"]=>
                    226:   float(2.2)
                    227:   ["re d"]=>
                    228:   string(5) "color"
                    229:   ["   Hello"]=>
                    230:   int(111)
                    231: }
                    232: - $preserve keys = true -
                    233: array(4) {
                    234:   ["pen
                    235: "]=>
                    236:   int(33)
                    237:   ["world"]=>
                    238:   float(2.2)
                    239:   ["re d"]=>
                    240:   string(5) "color"
                    241:   ["   Hello"]=>
                    242:   int(111)
                    243: }
                    244: - $preserve_keys = false -
                    245: array(4) {
                    246:   ["pen
                    247: "]=>
                    248:   int(33)
                    249:   ["world"]=>
                    250:   float(2.2)
                    251:   ["re d"]=>
                    252:   string(5) "color"
                    253:   ["   Hello"]=>
                    254:   int(111)
                    255: }
                    256: -- Iteration 8 --
                    257: - default argument -
                    258: array(4) {
                    259:   ["pen
                    260: "]=>
                    261:   int(33)
                    262:   ["world"]=>
                    263:   float(2.2)
                    264:   ["re d"]=>
                    265:   string(5) "color"
                    266:   ["   Hello"]=>
                    267:   int(111)
                    268: }
                    269: - $preserve keys = true -
                    270: array(4) {
                    271:   ["pen
                    272: "]=>
                    273:   int(33)
                    274:   ["world"]=>
                    275:   float(2.2)
                    276:   ["re d"]=>
                    277:   string(5) "color"
                    278:   ["   Hello"]=>
                    279:   int(111)
                    280: }
                    281: - $preserve_keys = false -
                    282: array(4) {
                    283:   ["pen
                    284: "]=>
                    285:   int(33)
                    286:   ["world"]=>
                    287:   float(2.2)
                    288:   ["re d"]=>
                    289:   string(5) "color"
                    290:   ["   Hello"]=>
                    291:   int(111)
                    292: }
                    293: -- Iteration 9 --
                    294: - default argument -
                    295: array(2) {
                    296:   ["Hello world"]=>
                    297:   string(6) "string"
                    298:   [0]=>
                    299:   string(5) "hello"
                    300: }
                    301: - $preserve keys = true -
                    302: array(2) {
                    303:   ["Hello world"]=>
                    304:   string(6) "string"
                    305:   [0]=>
                    306:   string(5) "hello"
                    307: }
                    308: - $preserve_keys = false -
                    309: array(2) {
                    310:   ["Hello world"]=>
                    311:   string(6) "string"
                    312:   [0]=>
                    313:   string(5) "hello"
                    314: }
                    315: -- Iteration 10 --
                    316: - default argument -
                    317: array(1) {
                    318:   [""]=>
                    319:   string(5) "hello"
                    320: }
                    321: - $preserve keys = true -
                    322: array(1) {
                    323:   [""]=>
                    324:   string(5) "hello"
                    325: }
                    326: - $preserve_keys = false -
                    327: array(1) {
                    328:   [""]=>
                    329:   string(5) "hello"
                    330: }
                    331: -- Iteration 11 --
                    332: - default argument -
                    333: array(6) {
                    334:   ["Hello world"]=>
                    335:   string(7) "heredoc"
                    336:   [""]=>
                    337:   string(5) "unset"
                    338:   [0]=>
                    339:   string(5) "float"
                    340:   [1]=>
                    341:   string(3) "int"
                    342:   ["fruit"]=>
                    343:   float(2.2)
                    344:   ["hello"]=>
                    345:   int(1)
                    346: }
                    347: - $preserve keys = true -
                    348: array(6) {
                    349:   ["Hello world"]=>
                    350:   string(7) "heredoc"
                    351:   [""]=>
                    352:   string(5) "unset"
                    353:   [444]=>
                    354:   string(5) "float"
                    355:   [133]=>
                    356:   string(3) "int"
                    357:   ["fruit"]=>
                    358:   float(2.2)
                    359:   ["hello"]=>
                    360:   int(1)
                    361: }
                    362: - $preserve_keys = false -
                    363: array(6) {
                    364:   ["Hello world"]=>
                    365:   string(7) "heredoc"
                    366:   [""]=>
                    367:   string(5) "unset"
                    368:   [0]=>
                    369:   string(5) "float"
                    370:   [1]=>
                    371:   string(3) "int"
                    372:   ["fruit"]=>
                    373:   float(2.2)
                    374:   ["hello"]=>
                    375:   int(1)
                    376: }
                    377: Done

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