1--TEST--
2Test uasort() function : usage variations - anonymous function as 'cmp_function'
3--FILE--
4<?php
5/*
6* Passing different anonymous functions as 'cmp_function'
7*   arguments passed by value
8*   arguments passed by reference
9*/
10
11echo "*** Testing uasort() : anonymous function as 'cmp_function' ***\n";
12
13$cmp_function = function($value1, $value2) {
14    if ($value1 == $value2) { return 0; }
15    else if ($value1 > $value2) { return 1; }
16    else { return -1; }
17};
18
19$array_arg = array(0 => 100, 1 => 3, 2 => -70, 3 => 24, 4 => 90);
20echo "-- Anonymous 'cmp_function' with parameters passed by value --\n";
21var_dump( uasort($array_arg, $cmp_function) );
22var_dump($array_arg);
23
24$cmp_function = function(&$value1, &$value2) {
25    if ($value1 == $value2) { return 0; }
26    else if ($value1 > $value2) { return 1; }
27    else { return -1; }
28};
29
30$array_arg = array("b" => "Banana", "m" => "Mango", "a" => "Apple", "p" => "Pineapple");
31echo "-- Anonymous 'cmp_function' with parameters passed by reference --\n";
32var_dump( uasort($array_arg, $cmp_function ) );
33var_dump($array_arg);
34
35echo "Done"
36?>
37--EXPECTF--
38*** Testing uasort() : anonymous function as 'cmp_function' ***
39-- Anonymous 'cmp_function' with parameters passed by value --
40bool(true)
41array(5) {
42  [2]=>
43  int(-70)
44  [1]=>
45  int(3)
46  [3]=>
47  int(24)
48  [4]=>
49  int(90)
50  [0]=>
51  int(100)
52}
53-- Anonymous 'cmp_function' with parameters passed by reference --
54
55Warning: {closure}(): Argument #1 ($value1) must be passed by reference, value given in %s on line %d
56
57Warning: {closure}(): Argument #2 ($value2) must be passed by reference, value given in %s on line %d
58
59Warning: {closure}(): Argument #1 ($value1) must be passed by reference, value given in %s on line %d
60
61Warning: {closure}(): Argument #2 ($value2) must be passed by reference, value given in %s on line %d
62
63Warning: {closure}(): Argument #1 ($value1) must be passed by reference, value given in %s on line %d
64
65Warning: {closure}(): Argument #2 ($value2) must be passed by reference, value given in %s on line %d
66
67Warning: {closure}(): Argument #1 ($value1) must be passed by reference, value given in %s on line %d
68
69Warning: {closure}(): Argument #2 ($value2) must be passed by reference, value given in %s on line %d
70bool(true)
71array(4) {
72  ["a"]=>
73  string(5) "Apple"
74  ["b"]=>
75  string(6) "Banana"
76  ["m"]=>
77  string(5) "Mango"
78  ["p"]=>
79  string(9) "Pineapple"
80}
81Done
82