我在应用程序中收到奇怪的警告通知。我在课堂中使用自定义usort
函数。这是它的外观:PHP注意:无法将Closure类的对象转换为int
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]);
};
}
}
这是通知我得到:
Notice: Object of class Closure could not be converted to int in PATH_TO_FILE on line xx
什么想法?
您的意思是'usort($阵列,自:: zstream_sorter( “the_key”))'? – Esailija
@Esailija是的,你是对的。星期六上午6:45在我的区域,在我的防守 –