Annotation of embedaddon/php/ext/standard/tests/array/arsort_object2.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test arsort() function : object functionality - sorting objects with diff. accessibility of member vars
3: --FILE--
4: <?php
5: /* Prototype : bool arsort ( array &$array [, int $asort_flags] )
6: * Description: Sort an array and maintain index association.
7: Elements will be arranged from highest to lowest when this function has completed.
8: * Source code: ext/standard/array.c
9: */
10:
11: /*
12: * testing arsort() by providing integer/string object arrays with following flag values
13: * 1. Defualt flag value
14: 2. SORT_REGULAR - compare items normally
15: */
16:
17: echo "*** Testing arsort() : object functionality ***\n";
18:
19: // class declaration for integer objects
20: class for_integer_arsort
21: {
22: public $public_class_value;
23: private $private_class_value;
24: protected $protected_class_value;
25: // initializing object member value
26: function __construct($value1, $value2,$value3){
27: $this->public_class_value = $value1;
28: $this->private_class_value = $value2;
29: $this->protected_class_value = $value3;
30: }
31:
32: }
33:
34: // class declaration for string objects
35: class for_string_arsort
36: {
37: public $public_class_value;
38: private $private_class_value;
39: protected $protected_class_value;
40: // initializing object member value
41: function __construct($value1, $value2,$value3){
42: $this->public_class_value = $value1;
43: $this->private_class_value = $value2;
44: $this->protected_class_value = $value3;
45: }
46:
47: // return string value
48: function __tostring() {
49: return (string)$this->value;
50: }
51: }
52:
53: // array of integer objects
54: $unsorted_int_obj = array (
55: 1 => new for_integer_arsort(11, 33,2), 2 => new for_integer_asort(44, 66,3),
56: 3 => new for_integer_arsort(23, 32,6), 4 => new for_integer_asort(-88, -5,-4),
57: );
58:
59: // array of string objects
60: $unsorted_str_obj = array (
61: "a" => new for_string_arsort("axx","AXX","d"), "b" => new for_string_asort("T", "t","q"),
62: "c" => new for_string_arsort("w", "W","c"), "d" => new for_string_asort("PY", "py","s"),
63: );
64:
65:
66: echo "\n-- Testing arsort() by supplying various object arrays, 'flag' value is default --\n";
67:
68: // testing arsort() function by supplying integer object array, flag value is default
69: $temp_array = $unsorted_int_obj;
70: var_dump(arsort($temp_array) );
71: var_dump($temp_array);
72:
73: // testing arsort() function by supplying string object array, flag value is default
74: $temp_array = $unsorted_str_obj;
75: var_dump(arsort($temp_array) );
76: var_dump($temp_array);
77:
78: echo "\n-- Testing arsort() by supplying various object arrays, 'flag' value is SORT_REGULAR --\n";
79: // testing arsort() function by supplying integer object array, flag value = SORT_REGULAR
80: $temp_array = $unsorted_int_obj;
81: var_dump(arsort($temp_array, SORT_REGULAR) );
82: var_dump($temp_array);
83:
84: // testing arsort() function by supplying string object array, flag value = SORT_REGULAR
85: $temp_array = $unsorted_str_obj;
86: var_dump(arsort($temp_array, SORT_REGULAR) );
87: var_dump($temp_array);
88:
89: echo "Done\n";
90: ?>
91: --EXPECTF--
92: *** Testing arsort() : object functionality ***
93:
94: Fatal error: Class 'for_integer_asort' not found in %sarsort_object2.php on line %d
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>