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

1.1       misho       1: --TEST--
                      2: Test array_intersect_uassoc() function : usage variation - Passing unexpected values to optional third argument
                      3: --FILE--
                      4: <?php
                      5: /* Prototype  : array array_intersect_uassoc(array arr1, array arr2 [, array ...], callback key_compare_func)
                      6:  * Description: Computes the intersection of arrays with additional index check, compares indexes by a callback function
                      7:  * Source code: ext/standard/array.c
                      8:  */
                      9: 
                     10: echo "*** Testing array_intersect_uassoc() : usage variation ***\n";
                     11: 
                     12: // Initialise function arguments 
                     13: $array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red");
                     14: $array2 = array("a" => "green", "yellow", "red");
                     15: 
                     16: //Callback function
                     17: function key_compare_func($a, $b) {
                     18:     if ($a === $b) {
                     19:         return 0;
                     20:     }
                     21:     return ($a > $b) ? 1 : -1;
                     22: }
                     23: 
                     24: //get an unset variable
                     25: $unset_var = 10;
                     26: unset ($unset_var);
                     27: 
                     28: //resource variable
                     29: $fp = fopen(__FILE__, "r");
                     30: 
                     31: // define some classes
                     32: class classWithToString
                     33: {
                     34:        public function __toString() {
                     35:                return "Class A object";
                     36:        }
                     37: }
                     38: 
                     39: class classWithoutToString
                     40: {
                     41: }
                     42: 
                     43: // heredoc string
                     44: $heredoc = <<<EOT
                     45: hello world
                     46: EOT;
                     47: 
                     48: // add arrays
                     49: $index_array = array (1, 2, 3);
                     50: $assoc_array = array ('one' => 1, 'two' => 2);
                     51: 
                     52: //array of values to iterate over
                     53: $inputs = array(
                     54: 
                     55:       // int data
                     56:       'int 0' => 0,
                     57:       'int 1' => 1,
                     58:       'int 12345' => 12345,
                     59:       'int -12345' => -12345,
                     60: 
                     61:       // float data
                     62:       'float 10.5' => 10.5,
                     63:       'float -10.5' => -10.5,
                     64:       'float 12.3456789000e10' => 12.3456789000e10,
                     65:       'float -12.3456789000e10' => -12.3456789000e10,
                     66:       'float .5' => .5,
                     67: 
                     68:       // null data
                     69:       'uppercase NULL' => NULL,
                     70:       'lowercase null' => null,
                     71: 
                     72:       // boolean data
                     73:       'lowercase true' => true,
                     74:       'lowercase false' =>false,
                     75:       'uppercase TRUE' =>TRUE,
                     76:       'uppercase FALSE' =>FALSE,
                     77: 
                     78:       // empty data
                     79:       'empty string DQ' => "",
                     80:       'empty string SQ' => '',
                     81: 
                     82:       // string data
                     83:       'string DQ' => "string",
                     84:       'string SQ' => 'string',
                     85:       'mixed case string' => "sTrInG",
                     86:       'heredoc' => $heredoc,
                     87: 
                     88:       // object data
                     89:       'instance of classWithToString' => new classWithToString(),
                     90:       'instance of classWithoutToString' => new classWithoutToString(),
                     91: 
                     92:       // undefined data
                     93:       'undefined var' => @$undefined_var,
                     94: 
                     95:       // unset data
                     96:       'unset var' => @$unset_var,
                     97: 
                     98:       // resource data
                     99:       'resource' => $fp,
                    100: );
                    101: 
                    102: // loop through each element of the array for arr1
                    103: foreach($inputs as $key =>$value) {
                    104:       echo "\n--$key--\n";
                    105:       var_dump( array_intersect_uassoc($array1, $array2, $value, 'key_compare_func') );
                    106: };
                    107: 
                    108: fclose($fp);
                    109: ?>
                    110: ===DONE===
                    111: --EXPECTF--
                    112: 
                    113: *** Testing array_intersect_uassoc() : usage variation ***
                    114: 
                    115: --int 0--
                    116: 
                    117: Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d
                    118: NULL
                    119: 
                    120: --int 1--
                    121: 
                    122: Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d
                    123: NULL
                    124: 
                    125: --int 12345--
                    126: 
                    127: Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d
                    128: NULL
                    129: 
                    130: --int -12345--
                    131: 
                    132: Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d
                    133: NULL
                    134: 
                    135: --float 10.5--
                    136: 
                    137: Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d
                    138: NULL
                    139: 
                    140: --float -10.5--
                    141: 
                    142: Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d
                    143: NULL
                    144: 
                    145: --float 12.3456789000e10--
                    146: 
                    147: Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d
                    148: NULL
                    149: 
                    150: --float -12.3456789000e10--
                    151: 
                    152: Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d
                    153: NULL
                    154: 
                    155: --float .5--
                    156: 
                    157: Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d
                    158: NULL
                    159: 
                    160: --uppercase NULL--
                    161: 
                    162: Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d
                    163: NULL
                    164: 
                    165: --lowercase null--
                    166: 
                    167: Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d
                    168: NULL
                    169: 
                    170: --lowercase true--
                    171: 
                    172: Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d
                    173: NULL
                    174: 
                    175: --lowercase false--
                    176: 
                    177: Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d
                    178: NULL
                    179: 
                    180: --uppercase TRUE--
                    181: 
                    182: Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d
                    183: NULL
                    184: 
                    185: --uppercase FALSE--
                    186: 
                    187: Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d
                    188: NULL
                    189: 
                    190: --empty string DQ--
                    191: 
                    192: Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d
                    193: NULL
                    194: 
                    195: --empty string SQ--
                    196: 
                    197: Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d
                    198: NULL
                    199: 
                    200: --string DQ--
                    201: 
                    202: Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d
                    203: NULL
                    204: 
                    205: --string SQ--
                    206: 
                    207: Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d
                    208: NULL
                    209: 
                    210: --mixed case string--
                    211: 
                    212: Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d
                    213: NULL
                    214: 
                    215: --heredoc--
                    216: 
                    217: Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d
                    218: NULL
                    219: 
                    220: --instance of classWithToString--
                    221: 
                    222: Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d
                    223: NULL
                    224: 
                    225: --instance of classWithoutToString--
                    226: 
                    227: Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d
                    228: NULL
                    229: 
                    230: --undefined var--
                    231: 
                    232: Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d
                    233: NULL
                    234: 
                    235: --unset var--
                    236: 
                    237: Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d
                    238: NULL
                    239: 
                    240: --resource--
                    241: 
                    242: Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d
                    243: NULL
                    244: ===DONE===

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