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

1.1       misho       1: --TEST--
                      2: Test end() function
                      3: --SKIPIF--
                      4: <?php
                      5: if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only");
                      6: ?>
                      7: --INI--
                      8: precision=14
                      9: --FILE--
                     10: <?php
                     11: /* Prototype: mixed end ( array &$array );
                     12:    Description: Advances internal pointer of array to last element, and returns its value.
                     13: */
                     14: 
                     15: $arrays = array (
                     16:   array( 0 ),
                     17:   range(1, 100 ),
                     18:   range('a', 'z', 2 ),
                     19:   array("a" => "A", 2 => "B", "C" => 3, 4 => 4, "one" => 1, "" => NULL ),
                     20:   array(1, array(1, 2 => 3 ), "one" => 1, "5" => 5 ),
                     21:   array(-1, -2, -3, -4, "-0.005" => "neg0.005", 2.0 => "float2", "neg.9" => -.9 ),
                     22:   array(1.0005, 2.000000, -3.000000, -4.9999999 ),
                     23:   array(true, false),
                     24:   array("PHP", "Web2.0", "SOA"),
                     25:   array(1, array() ),
                     26:   array(1, 2, "" ),
                     27:   array(" "),
                     28:   array(2147483647, 2147483648, -2147483647, -2147483648 ),
                     29:   array(0x7FFFFFFF, -0x80000000, 017777777777, -020000000000 ),
                     30:   array(-.6700000E+3, -4.10003E+3, 1e-5, -1E+5, 000002.00 )
                     31: );
                     32: /* loop through $arrays to print the last element of each sub-array */ 
                     33: echo "*** Testing end() on different arrays ***\n";
                     34: $counter = 1;
                     35: foreach ($arrays as $sub_array){
                     36:   echo "-- Iteration $counter --\n";
                     37:   var_dump( end($sub_array) );
                     38:   /* ensure that internal pointer is moved to last element */
                     39:   var_dump( current($sub_array) ); 
                     40:   $counter++;
                     41: }
                     42: 
                     43: /* checking for end() on sub-arrays */
                     44: echo "\n*** Testing end() with sub-arrays ***\n";
                     45: $test_array = array(1, array(1 => "one", "two" => 2, "" => "f") );
                     46: var_dump( end($test_array) );
                     47: var_dump( end($test_array[1]) );
                     48: 
                     49: /* checking working of end() when array elements are deleted */
                     50: echo "\n*** Testing end() when array elements are deleted ***\n";
                     51: $array_test = array("a", "b", "d", 7, "u" => "U", -4, "-.008" => "neg.008");
                     52: 
                     53: // remove first element from array 
                     54: echo "\n-- Remove first element from array --\n";
                     55: unset($array_test[0]);
                     56: var_dump( end($array_test) );
                     57: 
                     58: // remove last element from array, rewind and check end() 
                     59: echo "\n-- Remove last element from array --\n";
                     60: unset($array_test['-.008']);
                     61: var_dump( end($array_test) );
                     62: reset( $array_test );
                     63: var_dump( end($array_test) );
                     64: 
                     65: // remove any element  !first, !last, rewind and check end() 
                     66: echo "\n-- Remove any element from array apart from first and last element --\n";
                     67: unset($array_test[7]);
                     68: var_dump( end($array_test) );
                     69: var_dump( reset($array_test) );
                     70: var_dump( end($array_test) );
                     71: 
                     72: /* Checking on OBJECTS type */
                     73: echo "\n*** Testing end() on objects ***\n";
                     74: class foo
                     75: {
                     76:   function __toString() {
                     77:     return "Object";
                     78:   }
                     79: }
                     80: class foo1
                     81: {
                     82:   function __toString() {
                     83:     return "Object1";
                     84:   }
                     85: }
                     86: 
                     87: $object1 = new foo(); //new object created
                     88: $object2 = new foo1();
                     89: 
                     90: $array_object = array();
                     91: $array_object[0] = &$object1;
                     92: $array_object[1] = &$object2;
                     93: var_dump( end($array_object) );
                     94: var_dump($array_object);
                     95: 
                     96: /* Checking on RESOURCE type */
                     97: echo "\n*** Testing end() on resource type ***\n";
                     98: //file type resource
                     99: $file_handle = fopen(__FILE__, "r");
                    100: 
                    101: //directory type resource
                    102: $dir_handle = opendir( dirname(__FILE__) );
                    103: 
                    104: //store resources in array
                    105: $resources = array($file_handle, $dir_handle);
                    106: var_dump( end($resources) );
                    107: var_dump( current($resources) );
                    108: 
                    109: echo "\n*** Testing error conditions ***\n";
                    110: /* checking for unexpected number of arguments */
                    111: var_dump( end() );
                    112: var_dump( end($array[0], $array[0]) );
                    113: 
                    114: /* checking for unexpected type of arguments */
                    115: $var=1;
                    116: $var1="string";
                    117: var_dump( end($var) );
                    118: var_dump( end($var1) );
                    119: 
                    120: /* checking null array */
                    121: $null_array = array();
                    122: var_dump( end($null_array) );
                    123: 
                    124: echo "Done\n";
                    125: 
                    126: ?>
                    127: 
                    128: --CLEAN--
                    129: /* cleaning resource handles */
                    130: fclose( $file_handle );  //file resource handle deleted
                    131: closedir( $dir_handle );  //dir resource handle deleted
                    132: 
                    133: --EXPECTF--
                    134: *** Testing end() on different arrays ***
                    135: -- Iteration 1 --
                    136: int(0)
                    137: int(0)
                    138: -- Iteration 2 --
                    139: int(100)
                    140: int(100)
                    141: -- Iteration 3 --
                    142: string(1) "y"
                    143: string(1) "y"
                    144: -- Iteration 4 --
                    145: NULL
                    146: NULL
                    147: -- Iteration 5 --
                    148: int(5)
                    149: int(5)
                    150: -- Iteration 6 --
                    151: float(-0.9)
                    152: float(-0.9)
                    153: -- Iteration 7 --
                    154: float(-4.9999999)
                    155: float(-4.9999999)
                    156: -- Iteration 8 --
                    157: bool(false)
                    158: bool(false)
                    159: -- Iteration 9 --
                    160: string(3) "SOA"
                    161: string(3) "SOA"
                    162: -- Iteration 10 --
                    163: array(0) {
                    164: }
                    165: array(0) {
                    166: }
                    167: -- Iteration 11 --
                    168: string(0) ""
                    169: string(0) ""
                    170: -- Iteration 12 --
                    171: string(1) " "
                    172: string(1) " "
                    173: -- Iteration 13 --
                    174: int(-2147483648)
                    175: int(-2147483648)
                    176: -- Iteration 14 --
                    177: int(-2147483648)
                    178: int(-2147483648)
                    179: -- Iteration 15 --
                    180: float(2)
                    181: float(2)
                    182: 
                    183: *** Testing end() with sub-arrays ***
                    184: array(3) {
                    185:   [1]=>
                    186:   string(3) "one"
                    187:   ["two"]=>
                    188:   int(2)
                    189:   [""]=>
                    190:   string(1) "f"
                    191: }
                    192: string(1) "f"
                    193: 
                    194: *** Testing end() when array elements are deleted ***
                    195: 
                    196: -- Remove first element from array --
                    197: string(7) "neg.008"
                    198: 
                    199: -- Remove last element from array --
                    200: int(-4)
                    201: int(-4)
                    202: 
                    203: -- Remove any element from array apart from first and last element --
                    204: int(-4)
                    205: string(1) "b"
                    206: int(-4)
                    207: 
                    208: *** Testing end() on objects ***
                    209: object(foo1)#%d (0) {
                    210: }
                    211: array(2) {
                    212:   [0]=>
                    213:   &object(foo)#%d (0) {
                    214:   }
                    215:   [1]=>
                    216:   &object(foo1)#%d (0) {
                    217:   }
                    218: }
                    219: 
                    220: *** Testing end() on resource type ***
                    221: resource(%d) of type (stream)
                    222: resource(%d) of type (stream)
                    223: 
                    224: *** Testing error conditions ***
                    225: 
                    226: Warning: end() expects exactly 1 parameter, 0 given in %s on line %d
                    227: NULL
                    228: 
                    229: Warning: end() expects exactly 1 parameter, 2 given in %s on line %d
                    230: NULL
                    231: 
                    232: Warning: end() expects parameter 1 to be array, integer given in %s on line %d
                    233: NULL
                    234: 
                    235: Warning: end() expects parameter 1 to be array, string given in %s on line %d
                    236: NULL
                    237: bool(false)
                    238: Done

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