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

1.1       misho       1: --TEST--
                      2: Test array_intersect_uassoc() function : usage variation - Passing class/object methods to callback
                      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: //Initialize variables
                     13: $array1 = array("a" => "green", "c" => "blue", "red");
                     14: $array2 = array("a" => "green", "yellow", "red");
                     15: // define some class with method
                     16: class MyClass
                     17: {
                     18:        static function static_compare_func($a, $b) {
                     19:                return strcasecmp($a, $b);
                     20:        }
                     21:     
                     22:        public function class_compare_func($a, $b) {
                     23:                return strcasecmp($a, $b);
                     24:        }
                     25:        
                     26: }
                     27: 
                     28: echo "\n-- Testing array_intersect_uassoc() function using class with static method as callback --\n";
                     29: var_dump( array_intersect_uassoc($array1, $array2, array('MyClass','static_compare_func')) );
                     30: var_dump( array_intersect_uassoc($array1, $array2, 'MyClass::static_compare_func'));
                     31: 
                     32: echo "\n-- Testing array_intersect_uassoc() function using class with regular method as callback --\n";
                     33: $obj = new MyClass();
                     34: var_dump( array_intersect_uassoc($array1, $array2, array($obj,'class_compare_func')) );
                     35: ?>
                     36: ===DONE===
                     37: --EXPECTF--
                     38: *** Testing array_intersect_uassoc() : usage variation ***
                     39: 
                     40: -- Testing array_intersect_uassoc() function using class with static method as callback --
                     41: array(1) {
                     42:   ["a"]=>
                     43:   string(5) "green"
                     44: }
                     45: array(1) {
                     46:   ["a"]=>
                     47:   string(5) "green"
                     48: }
                     49: 
                     50: -- Testing array_intersect_uassoc() function using class with regular method as callback --
                     51: array(1) {
                     52:   ["a"]=>
                     53:   string(5) "green"
                     54: }
                     55: ===DONE===

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