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

1.1       misho       1: --TEST--
                      2: Test array_diff_assoc() function : variation - array containing different data types
                      3: --FILE--
                      4: <?php
                      5: /* Prototype  : array array_diff_assoc(array $arr1, array $arr2 [, array ...])
                      6:  * Description: Returns the entries of arr1 that have values which are not present 
                      7:  * in any of the others arguments but do additional checks whether the keys are equal 
                      8:  * Source code: ext/standard/array.c 
                      9:  */
                     10: 
                     11: /*
                     12:  * Test how array_diff_assoc() compares indexed arrays containing different data types
                     13:  */
                     14:  
                     15: echo "\n*** Testing array_diff_assoc() : usage variations ***\n";
                     16: 
                     17: $array = array(1, 2, 3);
                     18: 
                     19: //get an unset variable
                     20: $unset_var = 10;
                     21: unset ($unset_var);
                     22: 
                     23: // get a class
                     24: class classA
                     25: {
                     26:   public function __toString() {
                     27:     return "Class A object";
                     28:   }
                     29: }
                     30: 
                     31: // heredoc string
                     32: $heredoc = <<<EOT
                     33: hello world
                     34: EOT;
                     35: 
                     36: //array of different data types to be passed to $arr1 argument 
                     37: $inputs = array(
                     38: 
                     39:        // int data
                     40: /*1*/
                     41: 'int' => array(       
                     42:           0,
                     43:        1,
                     44:        12345,
                     45:        -2345),
                     46: 
                     47:        // float data
                     48: /*2*/
                     49: 'float' => array(       
                     50:        10.5,
                     51:        -10.5,
                     52:        12.3456789000e10,
                     53:        12.3456789000E-10,
                     54:        .5),
                     55: 
                     56:        // null data
                     57: /*3*/
                     58: 'null' => array(
                     59:        NULL,
                     60:        null),
                     61: 
                     62:        // boolean data
                     63: /*4*/
                     64: 'bool' => array(
                     65:        true,
                     66:        false,
                     67:        TRUE,
                     68:        FALSE),
                     69:        
                     70:        // empty data
                     71: /*5*/
                     72: 'empty' => array(
                     73:        "",
                     74:        ''),
                     75: 
                     76:        // string data
                     77: /*6*/
                     78: 'string' => array(
                     79:        "string",
                     80:        'string',
                     81:        $heredoc),
                     82:        
                     83:        // binary data
                     84: /*7*/
                     85: 'binary' => array(
                     86:        b"binary",
                     87:           (binary)"binary"),
                     88:           
                     89:        // object data
                     90: /*8*/
                     91: 'object' => array(
                     92:       new classA()),
                     93: 
                     94:        // undefined data
                     95: /*9*/
                     96: 'undefined' => array(
                     97:        @$undefined_var),
                     98: 
                     99:        // unset data
                    100: /*10*/
                    101: 'unset' => array(
                    102:       @$unset_var),
                    103: );
                    104: 
                    105: // loop through each element of $inputs to check the behavior of array_diff_assoc
                    106: $iterator = 1;
                    107: foreach($inputs as $key => $input) {
                    108:   echo "\n-- Iteration $iterator --\n";
                    109:   var_dump( array_diff_assoc($input, $array));
                    110:   $iterator++;
                    111: };
                    112: echo "Done";
                    113: ?>
                    114: --EXPECTF--
                    115: 
                    116: *** Testing array_diff_assoc() : usage variations ***
                    117: 
                    118: -- Iteration 1 --
                    119: array(4) {
                    120:   [0]=>
                    121:   int(0)
                    122:   [1]=>
                    123:   int(1)
                    124:   [2]=>
                    125:   int(12345)
                    126:   [3]=>
                    127:   int(-2345)
                    128: }
                    129: 
                    130: -- Iteration 2 --
                    131: array(5) {
                    132:   [0]=>
                    133:   float(10.5)
                    134:   [1]=>
                    135:   float(-10.5)
                    136:   [2]=>
                    137:   float(123456789000)
                    138:   [3]=>
                    139:   float(1.23456789E-9)
                    140:   [4]=>
                    141:   float(0.5)
                    142: }
                    143: 
                    144: -- Iteration 3 --
                    145: array(2) {
                    146:   [0]=>
                    147:   NULL
                    148:   [1]=>
                    149:   NULL
                    150: }
                    151: 
                    152: -- Iteration 4 --
                    153: array(3) {
                    154:   [1]=>
                    155:   bool(false)
                    156:   [2]=>
                    157:   bool(true)
                    158:   [3]=>
                    159:   bool(false)
                    160: }
                    161: 
                    162: -- Iteration 5 --
                    163: array(2) {
                    164:   [0]=>
                    165:   string(0) ""
                    166:   [1]=>
                    167:   string(0) ""
                    168: }
                    169: 
                    170: -- Iteration 6 --
                    171: array(3) {
                    172:   [0]=>
                    173:   string(6) "string"
                    174:   [1]=>
                    175:   string(6) "string"
                    176:   [2]=>
                    177:   string(11) "hello world"
                    178: }
                    179: 
                    180: -- Iteration 7 --
                    181: array(2) {
                    182:   [0]=>
                    183:   string(6) "binary"
                    184:   [1]=>
                    185:   string(6) "binary"
                    186: }
                    187: 
                    188: -- Iteration 8 --
                    189: array(1) {
                    190:   [0]=>
                    191:   object(classA)#%d (0) {
                    192:   }
                    193: }
                    194: 
                    195: -- Iteration 9 --
                    196: array(1) {
                    197:   [0]=>
                    198:   NULL
                    199: }
                    200: 
                    201: -- Iteration 10 --
                    202: array(1) {
                    203:   [0]=>
                    204:   NULL
                    205: }
                    206: Done

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