import zend standard tests
[hiphop-php.git] / hphp / test / zend / bad / ext-standard-array / usort_variation1.php
blobdd84d6518fb5ac9c3afced5d8ab6de77782a9705
1 <?php
2 /* Prototype : bool usort(array $array_arg, string $cmp_function)
3 * Description: Sort an array by values using a user-defined comparison function
4 * Source code: ext/standard/array.c
5 */
7 /*
8 * Pass different data types as $array_arg argument to usort() to test behaviour
9 */
11 echo "*** Testing usort() : usage variations ***\n";
13 // Initialise function arguments not being substituted
14 function cmp_function($value1, $value2)
16 if($value1 == $value2) {
17 return 0;
19 else if($value1 > $value2) {
20 return 1;
22 else {
23 return -1;
27 //get an unset variable
28 $unset_var = 10;
29 unset ($unset_var);
31 // get a class
32 class classA
34 public function __toString() {
35 return "Class A object";
39 // heredoc string
40 $heredoc = <<<EOT
41 hello world
42 EOT;
44 // get a resource variable
45 $fp = fopen(__FILE__, "r");
47 // unexpected values to be passed to $array_arg argument
48 $inputs = array(
50 // int data
51 /*1*/ 0,
53 12345,
54 -2345,
56 // float data
57 /*5*/ 10.5,
58 -10.5,
59 12.3456789000e10,
60 12.3456789000E-10,
61 .5,
63 // null data
64 /*10*/ NULL,
65 null,
67 // boolean data
68 /*12*/ true,
69 false,
70 TRUE,
71 FALSE,
73 // empty data
74 /*16*/ "",
75 '',
76 array(),
78 // string data
79 /*19*/ "string",
80 'string',
81 $heredoc,
83 // object data
84 /*22*/ new classA(),
86 // undefined data
87 /*23*/ @$undefined_var,
89 // unset data
90 /*24*/ @$unset_var,
92 // resource variable
93 /*25*/ $fp
96 // loop through each element of $inputs to check the behavior of usort()
97 $iterator = 1;
98 foreach($inputs as $input) {
99 echo "\n-- Iteration $iterator --\n";
100 var_dump( usort($input, 'cmp_function') );
101 $iterator++;
104 //closing resource
105 fclose($fp);
107 ===DONE===