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

1.1       misho       1: --TEST--
                      2: Test rsort() function : usage variations - Pass different data types as $sort_flags arg
                      3: --FILE--
                      4: <?php
                      5: /* Prototype  : bool rsort(array &$array_arg [, int $sort_flags])
                      6:  * Description: Sort an array in reverse order 
                      7:  * Source code: ext/standard/array.c
                      8:  */
                      9: 
                     10: /*
                     11:  * Pass different data types as $sort_flags argument to rsort() to test behaviour
                     12:  * Where possible, 'SORT_NUMERIC' has been entered as a string value
                     13:  */
                     14: 
                     15: echo "*** Testing rsort() : variation ***\n";
                     16: 
                     17: // Initialise function arguments not being substituted
                     18: $array_arg = array (1, 5, 2, 3, 1);
                     19: 
                     20: //get an unset variable
                     21: $unset_var = 10;
                     22: unset ($unset_var);
                     23: 
                     24: // get a class
                     25: class classA
                     26: {
                     27:   public function __toString() {
                     28:     return "SORT_NUMERIC";
                     29:   }
                     30: }
                     31: 
                     32: // heredoc string
                     33: $heredoc = <<<EOT
                     34: SORT_NUMERIC
                     35: EOT;
                     36: 
                     37: // get a resource variable
                     38: $fp = fopen(__FILE__, "r");
                     39: 
                     40: // unexpected values to be passed to $sort_flags argument
                     41: $inputs = array(
                     42: 
                     43:        // int data
                     44: /*1*/  0,
                     45:        1,
                     46:        12345,
                     47:        -2345,
                     48: 
                     49:        // float data
                     50: /*5*/  10.5,
                     51:        -10.5,
                     52:        12.3456789000e10,
                     53:        12.3456789000E-10,
                     54:        .5,
                     55: 
                     56:        // null data
                     57: /*10*/ NULL,
                     58:        null,
                     59: 
                     60:        // boolean data
                     61: /*12*/ true,
                     62:        false,
                     63:        TRUE,
                     64:        FALSE,
                     65:        
                     66:        // empty data
                     67: /*16*/ "",
                     68:        '',
                     69: 
                     70:        // string data
                     71: /*18*/ "SORT_NUMERIC",
                     72:        'SORT_NUMERIC',
                     73:        $heredoc,
                     74:        
                     75:        // object data
                     76: /*21*/ new classA(),
                     77: 
                     78:        // undefined data
                     79: /*22*/ @$undefined_var,
                     80: 
                     81:        // unset data
                     82: /*23*/ @$unset_var,
                     83: 
                     84:        // resource variable
                     85: /*24*/ $fp
                     86: );
                     87: 
                     88: // loop through each element of $inputs to check the behavior of rsort()
                     89: $iterator = 1;
                     90: foreach($inputs as $input) {
                     91:   echo "\n-- Iteration $iterator --\n";
                     92:   
                     93:   //create temporary array in case rsort() works
                     94:   $temp = $array_arg;
                     95:   
                     96:   var_dump( rsort($temp, $input) );
                     97:   var_dump($temp);
                     98:   $iterator++;
                     99:   
                    100:   $temp = null;
                    101: };
                    102: 
                    103: fclose($fp);
                    104: 
                    105: echo "Done";
                    106: ?>
                    107: 
                    108: --EXPECTF--
                    109: *** Testing rsort() : variation ***
                    110: 
                    111: -- Iteration 1 --
                    112: bool(true)
                    113: array(5) {
                    114:   [0]=>
                    115:   int(5)
                    116:   [1]=>
                    117:   int(3)
                    118:   [2]=>
                    119:   int(2)
                    120:   [3]=>
                    121:   int(1)
                    122:   [4]=>
                    123:   int(1)
                    124: }
                    125: 
                    126: -- Iteration 2 --
                    127: bool(true)
                    128: array(5) {
                    129:   [0]=>
                    130:   int(5)
                    131:   [1]=>
                    132:   int(3)
                    133:   [2]=>
                    134:   int(2)
                    135:   [3]=>
                    136:   int(1)
                    137:   [4]=>
                    138:   int(1)
                    139: }
                    140: 
                    141: -- Iteration 3 --
                    142: bool(true)
                    143: array(5) {
                    144:   [0]=>
                    145:   int(5)
                    146:   [1]=>
                    147:   int(3)
                    148:   [2]=>
                    149:   int(2)
                    150:   [3]=>
                    151:   int(1)
                    152:   [4]=>
                    153:   int(1)
                    154: }
                    155: 
                    156: -- Iteration 4 --
                    157: bool(true)
                    158: array(5) {
                    159:   [0]=>
                    160:   int(5)
                    161:   [1]=>
                    162:   int(3)
                    163:   [2]=>
                    164:   int(2)
                    165:   [3]=>
                    166:   int(1)
                    167:   [4]=>
                    168:   int(1)
                    169: }
                    170: 
                    171: -- Iteration 5 --
                    172: bool(true)
                    173: array(5) {
                    174:   [0]=>
                    175:   int(5)
                    176:   [1]=>
                    177:   int(3)
                    178:   [2]=>
                    179:   int(2)
                    180:   [3]=>
                    181:   int(1)
                    182:   [4]=>
                    183:   int(1)
                    184: }
                    185: 
                    186: -- Iteration 6 --
                    187: bool(true)
                    188: array(5) {
                    189:   [0]=>
                    190:   int(5)
                    191:   [1]=>
                    192:   int(3)
                    193:   [2]=>
                    194:   int(2)
                    195:   [3]=>
                    196:   int(1)
                    197:   [4]=>
                    198:   int(1)
                    199: }
                    200: 
                    201: -- Iteration 7 --
                    202: bool(true)
                    203: array(5) {
                    204:   [0]=>
                    205:   int(5)
                    206:   [1]=>
                    207:   int(3)
                    208:   [2]=>
                    209:   int(2)
                    210:   [3]=>
                    211:   int(1)
                    212:   [4]=>
                    213:   int(1)
                    214: }
                    215: 
                    216: -- Iteration 8 --
                    217: bool(true)
                    218: array(5) {
                    219:   [0]=>
                    220:   int(5)
                    221:   [1]=>
                    222:   int(3)
                    223:   [2]=>
                    224:   int(2)
                    225:   [3]=>
                    226:   int(1)
                    227:   [4]=>
                    228:   int(1)
                    229: }
                    230: 
                    231: -- Iteration 9 --
                    232: bool(true)
                    233: array(5) {
                    234:   [0]=>
                    235:   int(5)
                    236:   [1]=>
                    237:   int(3)
                    238:   [2]=>
                    239:   int(2)
                    240:   [3]=>
                    241:   int(1)
                    242:   [4]=>
                    243:   int(1)
                    244: }
                    245: 
                    246: -- Iteration 10 --
                    247: bool(true)
                    248: array(5) {
                    249:   [0]=>
                    250:   int(5)
                    251:   [1]=>
                    252:   int(3)
                    253:   [2]=>
                    254:   int(2)
                    255:   [3]=>
                    256:   int(1)
                    257:   [4]=>
                    258:   int(1)
                    259: }
                    260: 
                    261: -- Iteration 11 --
                    262: bool(true)
                    263: array(5) {
                    264:   [0]=>
                    265:   int(5)
                    266:   [1]=>
                    267:   int(3)
                    268:   [2]=>
                    269:   int(2)
                    270:   [3]=>
                    271:   int(1)
                    272:   [4]=>
                    273:   int(1)
                    274: }
                    275: 
                    276: -- Iteration 12 --
                    277: bool(true)
                    278: array(5) {
                    279:   [0]=>
                    280:   int(5)
                    281:   [1]=>
                    282:   int(3)
                    283:   [2]=>
                    284:   int(2)
                    285:   [3]=>
                    286:   int(1)
                    287:   [4]=>
                    288:   int(1)
                    289: }
                    290: 
                    291: -- Iteration 13 --
                    292: bool(true)
                    293: array(5) {
                    294:   [0]=>
                    295:   int(5)
                    296:   [1]=>
                    297:   int(3)
                    298:   [2]=>
                    299:   int(2)
                    300:   [3]=>
                    301:   int(1)
                    302:   [4]=>
                    303:   int(1)
                    304: }
                    305: 
                    306: -- Iteration 14 --
                    307: bool(true)
                    308: array(5) {
                    309:   [0]=>
                    310:   int(5)
                    311:   [1]=>
                    312:   int(3)
                    313:   [2]=>
                    314:   int(2)
                    315:   [3]=>
                    316:   int(1)
                    317:   [4]=>
                    318:   int(1)
                    319: }
                    320: 
                    321: -- Iteration 15 --
                    322: bool(true)
                    323: array(5) {
                    324:   [0]=>
                    325:   int(5)
                    326:   [1]=>
                    327:   int(3)
                    328:   [2]=>
                    329:   int(2)
                    330:   [3]=>
                    331:   int(1)
                    332:   [4]=>
                    333:   int(1)
                    334: }
                    335: 
                    336: -- Iteration 16 --
                    337: 
                    338: Warning: rsort() expects parameter 2 to be long, string given in %s on line %d
                    339: bool(false)
                    340: array(5) {
                    341:   [0]=>
                    342:   int(1)
                    343:   [1]=>
                    344:   int(5)
                    345:   [2]=>
                    346:   int(2)
                    347:   [3]=>
                    348:   int(3)
                    349:   [4]=>
                    350:   int(1)
                    351: }
                    352: 
                    353: -- Iteration 17 --
                    354: 
                    355: Warning: rsort() expects parameter 2 to be long, string given in %s on line %d
                    356: bool(false)
                    357: array(5) {
                    358:   [0]=>
                    359:   int(1)
                    360:   [1]=>
                    361:   int(5)
                    362:   [2]=>
                    363:   int(2)
                    364:   [3]=>
                    365:   int(3)
                    366:   [4]=>
                    367:   int(1)
                    368: }
                    369: 
                    370: -- Iteration 18 --
                    371: 
                    372: Warning: rsort() expects parameter 2 to be long, string given in %s on line %d
                    373: bool(false)
                    374: array(5) {
                    375:   [0]=>
                    376:   int(1)
                    377:   [1]=>
                    378:   int(5)
                    379:   [2]=>
                    380:   int(2)
                    381:   [3]=>
                    382:   int(3)
                    383:   [4]=>
                    384:   int(1)
                    385: }
                    386: 
                    387: -- Iteration 19 --
                    388: 
                    389: Warning: rsort() expects parameter 2 to be long, string given in %s on line %d
                    390: bool(false)
                    391: array(5) {
                    392:   [0]=>
                    393:   int(1)
                    394:   [1]=>
                    395:   int(5)
                    396:   [2]=>
                    397:   int(2)
                    398:   [3]=>
                    399:   int(3)
                    400:   [4]=>
                    401:   int(1)
                    402: }
                    403: 
                    404: -- Iteration 20 --
                    405: 
                    406: Warning: rsort() expects parameter 2 to be long, string given in %s on line %d
                    407: bool(false)
                    408: array(5) {
                    409:   [0]=>
                    410:   int(1)
                    411:   [1]=>
                    412:   int(5)
                    413:   [2]=>
                    414:   int(2)
                    415:   [3]=>
                    416:   int(3)
                    417:   [4]=>
                    418:   int(1)
                    419: }
                    420: 
                    421: -- Iteration 21 --
                    422: 
                    423: Warning: rsort() expects parameter 2 to be long, object given in %s on line %d
                    424: bool(false)
                    425: array(5) {
                    426:   [0]=>
                    427:   int(1)
                    428:   [1]=>
                    429:   int(5)
                    430:   [2]=>
                    431:   int(2)
                    432:   [3]=>
                    433:   int(3)
                    434:   [4]=>
                    435:   int(1)
                    436: }
                    437: 
                    438: -- Iteration 22 --
                    439: bool(true)
                    440: array(5) {
                    441:   [0]=>
                    442:   int(5)
                    443:   [1]=>
                    444:   int(3)
                    445:   [2]=>
                    446:   int(2)
                    447:   [3]=>
                    448:   int(1)
                    449:   [4]=>
                    450:   int(1)
                    451: }
                    452: 
                    453: -- Iteration 23 --
                    454: bool(true)
                    455: array(5) {
                    456:   [0]=>
                    457:   int(5)
                    458:   [1]=>
                    459:   int(3)
                    460:   [2]=>
                    461:   int(2)
                    462:   [3]=>
                    463:   int(1)
                    464:   [4]=>
                    465:   int(1)
                    466: }
                    467: 
                    468: -- Iteration 24 --
                    469: 
                    470: Warning: rsort() expects parameter 2 to be long, resource given in %s on line %d
                    471: bool(false)
                    472: array(5) {
                    473:   [0]=>
                    474:   int(1)
                    475:   [1]=>
                    476:   int(5)
                    477:   [2]=>
                    478:   int(2)
                    479:   [3]=>
                    480:   int(3)
                    481:   [4]=>
                    482:   int(1)
                    483: }
                    484: Done

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