PHP Notice: Object of class Closure could not be converted to int

php

Solution

`usort` is going to call `Class_Name::stream_sorter` as the comparison function, passing it two arguments. The return value is a function, but `usort` expects an integer telling it which of the arguments was greater. You need to pass the return value of `Class_Name::stream_sorter` to `usort`, not the function itself:

usort($array, self::zstream_sorter());

Problem

I'm getting a strange warning notice in my application. I'm using a custom `usort` function inside a class. This is how it looks: ``` class Class_Name { function zstream_builder() { $array = some_array(); //sort posts by date DESC usort($array, array('Class_Name', 'zstream_sorter')); // <- the notice is thrown on this line return $array; } private static function zstream_sorter($key = 'sort_str_date') { return function ($a, $b) use ($key) { return strnatcmp($a[$key], $b[$key]); }; } } ``` this is the notice I get: `Notice: Object of class Closure could not be converted to int in PATH_TO_FILE on line xx` any ideas?

Original source