convert ***sort builtins to use inout instead of references
[hiphop-php.git] / hphp / test / zend / good / ext / standard / tests / array / sort_object2.php
blob3753c1397874b9ae1be6dab4bb8a7ee809229f06
1 <?hh
2 /* Prototype : bool sort ( array &$array [, int $sort_flags] )
3 * Description: This function sorts an array.
4 Elements will be arranged from lowest to highest when this function has completed.
5 * Source code: ext/standard/array.c
6 */
8 /*
9 * testing sort() by providing integer/string object arrays with flag values are defualt, SORT_REGULAR
12 // class declaration for integer objects
13 class for_integer_sort
15 public $public_class_value;
16 private $private_class_value;
17 protected $protected_class_value;
19 // initializing object member value
20 function __construct($value1, $value2,$value3){
21 $this->public_class_value = $value1;
22 $this->private_class_value = $value2;
23 $this->protected_class_value = $value3;
27 // class declaration for string objects
28 class for_string_sort
30 public $public_class_value;
31 private $private_class_value;
32 protected $protected_class_value;
33 // initializing object member value
34 function __construct($value1, $value2,$value3){
35 $this->public_class_value = $value1;
36 $this->private_class_value = $value2;
37 $this->protected_class_value = $value3;
40 // return string value
41 function __tostring() {
42 return (string)$this->value;
46 <<__EntryPoint>> function main(): void {
47 echo "*** Testing sort() : object functionality ***\n";
49 // array of integer objects
50 $unsorted_int_obj = array(
51 new for_integer_sort(11,33,30),
52 new for_integer_sort(66,44,4),
53 new for_integer_sort(-88,-5,5),
54 new for_integer_sort(0.001,99.5,0.1)
57 // array of string objects
58 $unsorted_str_obj = array (
59 new for_string_sort("axx","AXX","ass"),
60 new for_string_sort("t","eee","abb"),
61 new for_string_sort("w","W", "c"),
62 new for_string_sort("py","PY", "pt"),
66 echo "\n-- Testing sort() by supplying various object arrays, 'flag' value is defualt --\n";
68 // testing sort() function by supplying integer object array, flag value is defualt
69 $temp_array = $unsorted_int_obj;
70 var_dump(sort(inout $temp_array) );
71 var_dump($temp_array);
73 // testing sort() function by supplying string object array, flag value is defualt
74 $temp_array = $unsorted_str_obj;
75 var_dump(sort(inout $temp_array) );
76 var_dump($temp_array);
78 echo "\n-- Testing sort() by supplying various object arrays, 'flag' value is SORT_REGULAR --\n";
79 // testing sort() function by supplying integer object array, flag value = SORT_REGULAR
80 $temp_array = $unsorted_int_obj;
81 var_dump(sort(inout $temp_array, SORT_REGULAR) );
82 var_dump($temp_array);
84 // testing sort() function by supplying string object array, flag value = SORT_REGULAR
85 $temp_array = $unsorted_str_obj;
86 var_dump(sort(inout $temp_array, SORT_REGULAR) );
87 var_dump($temp_array);
89 echo "Done\n";