Hello,
I have such a snippet in sorts:
$status_weights = array(
'waiting' => 3,
'ok' => 2,
'denied' => 1,
);
return $status_weights[$row1->field_offer_status] - $status_weights[$row2->field_offer_status];
But it gives me a bunch of warnings like this:
Warning: Parameter 3 to __lambda_func() expected to be a reference, value given in function views_php_handler_sort->php_sort() (line 85 in file /var/www/user678/data/www/pazzler.vashnet.ru/sites/all/modules/views_php/plugins/views/views_php_handler_sort.inc).
Warning: usort(): Array was modified by the user comparison function in function views_php_handler_sort->php_post_execute() (line 75 in file /var/www/user678/data/www/pazzler.vashnet.ru/sites/all/modules/views_php/plugins/views/views_php_handler_sort.inc
Comments
Comment #1
casey commentedThanks, I'll look into it (today hopefully)
Comment #2
casey commentedI think I fixed it. Please let me know if it works now.
Comment #3
casey commentedWell, I guess it does.
Comment #5
playfulwolf commentedHave a view table like:
some field | PHP field
--------------------------------
wegtwetqt | 0
wefwerewr | 0
ghhhhhhh | 1
34y34y34y | 0
34t3434y3 | 1
Ok, I have tried to sort with similar snippet in table view, but it only sorts the first row, like
some field | PHP field
--------------------------------
ghhhhhhh | 1
wegtwetqt | 0
wefwerewr | 0
34y34y34y | 0
34t3434y3 | 1
Can anyone confirm this behavior? Actually I am trying to sort "new_comments" of a node, which are not sortable by Views design
Comment #6
liquidcms commented@playfulwolf: how is your post even vaguely related to this thread?
Comment #7
liquidcms commentedi have a couple php sorts defined. on one of my pages i get a few of these:
Warning: usort() [function.usort]: Array was modified by the user comparison function in views_php_handler_sort->php_post_execute() (line 75 of E:\wamp\www\boma\sites\all\modules\views_php\plugins\views\views_php_handler_sort.inc).
doing a little digging i found this post: http://stackoverflow.com/questions/3235387/usort-array-was-modified-by-t...
which suggests that any error handling done within usort() (used by views_php) routine will cause this error. since drupal catches every error (even notices like $index not found) then it is nearly impossible to make much of a sort routine which doesn't have usort.
i decided to simply suppress errors during my sort routine using the @ operator. so my sort routine looked like this:
and _boma_region_tabs_view_sort_callback_value() call a much larger program to do the heavy lifting.. which hits drupal's error handler numerous times.
i am pretty sure views_php could do the suppression; but rather than fix that i simply modified my sort routine to this:
and no more errors.
Comment #8
spdeepak commentedWarning: usort(): Array was modified by the user comparison function in views_php_handler_sort->php_post_execute() (line 75 of /var/www/sites/all/modules/views_php/plugins/views/views_php_handler_sort.inc).I still get this error.
Comment #9
dgastudio commentedsame here
my code