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

1.1       misho       1: --TEST--
                      2: Test natcasesort() function : object functionality - mixed visibility within objects
                      3: --FILE--
                      4: <?php
                      5: /* Prototype  : bool natcasesort(array &$array_arg)
                      6:  * Description: Sort an array using case-insensitive natural sort
                      7:  * Source code: ext/standard/array.c
                      8:  */
                      9: 
                     10: /*
                     11:  * Pass natcasesort() an array of objects which have properties of different
                     12:  * visibilities to test how it re-orders the array.
                     13:  */
                     14: 
                     15: echo "*** Testing natcasesort() : object functionality ***\n";
                     16: 
                     17: // class declaration for string objects
                     18: class for_string_natcasesort
                     19: {
                     20:        public $public_class_value;
                     21:        private $private_class_value;
                     22:        protected $protected_class_value;
                     23:        // initializing object member value
                     24:        function __construct($value1, $value2,$value3){
                     25:                $this->public_class_value = $value1;
                     26:                $this->private_class_value = $value2;
                     27:                $this->protected_class_value = $value3;
                     28:        }
                     29: 
                     30:        // return string value
                     31:        function __tostring() {
                     32:                return (string)$this->public_class_value;
                     33:        }
                     34: 
                     35: }
                     36: 
                     37: // array of string objects
                     38: $unsorted_str_obj = array (
                     39: new for_string_natcasesort("axx","AXX","ass"),
                     40: new for_string_natcasesort("t","eee","abb"),
                     41: new for_string_natcasesort("w","W", "c"),
                     42: new for_string_natcasesort("py","PY", "pt"),
                     43: );
                     44: 
                     45: 
                     46: echo "\n-- Testing natcasesort() by supplying object arrays --\n";
                     47: 
                     48: // testing natcasesort() function by supplying string object array
                     49: $temp_array = $unsorted_str_obj;
                     50: var_dump(natcasesort($temp_array) );
                     51: var_dump($temp_array);
                     52: 
                     53: echo "Done";
                     54: ?>
                     55: 
                     56: --EXPECTF--
                     57: *** Testing natcasesort() : object functionality ***
                     58: 
                     59: -- Testing natcasesort() by supplying object arrays --
                     60: bool(true)
                     61: array(4) {
                     62:   [0]=>
                     63:   object(for_string_natcasesort)#%d (3) {
                     64:     ["public_class_value"]=>
                     65:     string(3) "axx"
                     66:     ["private_class_value":"for_string_natcasesort":private]=>
                     67:     string(3) "AXX"
                     68:     ["protected_class_value":protected]=>
                     69:     string(3) "ass"
                     70:   }
                     71:   [3]=>
                     72:   object(for_string_natcasesort)#%d (3) {
                     73:     ["public_class_value"]=>
                     74:     string(2) "py"
                     75:     ["private_class_value":"for_string_natcasesort":private]=>
                     76:     string(2) "PY"
                     77:     ["protected_class_value":protected]=>
                     78:     string(2) "pt"
                     79:   }
                     80:   [1]=>
                     81:   object(for_string_natcasesort)#%d (3) {
                     82:     ["public_class_value"]=>
                     83:     string(1) "t"
                     84:     ["private_class_value":"for_string_natcasesort":private]=>
                     85:     string(3) "eee"
                     86:     ["protected_class_value":protected]=>
                     87:     string(3) "abb"
                     88:   }
                     89:   [2]=>
                     90:   object(for_string_natcasesort)#%d (3) {
                     91:     ["public_class_value"]=>
                     92:     string(1) "w"
                     93:     ["private_class_value":"for_string_natcasesort":private]=>
                     94:     string(1) "W"
                     95:     ["protected_class_value":protected]=>
                     96:     string(1) "c"
                     97:   }
                     98: }
                     99: Done

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