Callbacks, like the one used by usort, can be specified in 3 different ways:
a string containing the name of the function:
usort($mylist, 'compare_foos');
an actual function:
usort($mylist, create_function(/*...*/));
// php >= 5.3 only:
usort($mylist, function ($a, $b) {
/* ... */
});
an array to access object methods:
usort($mylist, array($myobject, 'mymethod'));
Using a callback the way you did is not valid and php returns an error:
PHP Notice: Use of undefined constant compare_foos - assumed 'compare_foos' in /home/lepidosteus/test.php on line 28
To see it, remember to code with every error enabled on your development machine (but hide them on the production server), using error_reporting():
error_reporting(E_ALL); // display all errors including notices
error_reporting(0); // hide all errors
By the way if you want to use an object as a simple store, you don't need to create a dedicated class you can use stdClass():
$mylist[$i] = new stdClass();
$mylist[$i]->idx = $i;
$mylist[$i]->data = rand() % 20;
Also, you can use var_dump() instead of print_r when you debug to get detailed information about the type of each variable, can help you quickly find out if something is wrong.