Hello,

I have such a snippet in sorts:

<?php
$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

casey’s picture

Thanks, I'll look into it (today hopefully)

casey’s picture

I think I fixed it. Please let me know if it works now.

casey’s picture

Status:Active» Fixed

Well, I guess it does.

Status:Fixed» Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

PlayfulWolf’s picture

Status:Closed (fixed)» Active

Have 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

liquidcms’s picture

@playfulwolf: how is your post even vaguely related to this thread?

liquidcms’s picture

i 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:

function boma_region_tabs_view_sort_callback($row1nid, $row2nid) {
  if (_boma_region_tabs_view_sort_callback_value($row1nid) > _boma_region_tabs_view_sort_callback_value($row2nid)) {
    return 1;
  }
  return -1;
}

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:

function boma_region_tabs_view_sort_callback($row1nid, $row2nid) {
  if (@_boma_region_tabs_view_sort_callback_value($row1nid) > @_boma_region_tabs_view_sort_callback_value($row2nid)) {
    return 1;
  }
  return -1;
}

and no more errors.

spdeepak’s picture

Warning: 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.

kervi’s picture

same here

my code

<?php
$formula_1
= 0;
$formula_2 = 0;

$nid = $row1->nid;
$vote_1 = fivestar_get_votes('node', $nid, 'vote1', NULL);
$vote_1 = $vote_1['average']['value'];
$vote_2 = fivestar_get_votes('node', $nid, 'vote2', NULL);
$vote_2 = $vote_2['average']['value'];
$vote_3 = fivestar_get_votes('node', $nid, 'vote3', NULL);
$vote_3 = $vote_3['average']['value'];
$vote_4 = fivestar_get_votes('node', $nid, 'vote4', NULL);
$vote_4 = $vote_4['average']['value'];
$formula_1 = ($vote_1+$vote_2+$vote_3+$vote_4)/10;

$nid = $row2->nid;
$vote_1 = fivestar_get_votes('node', $nid, 'vote1', NULL);
$vote_1 = $vote_1['average']['value'];
$vote_2 = fivestar_get_votes('node', $nid, 'vote2', NULL);
$vote_2 = $vote_2['average']['value'];
$vote_3 = fivestar_get_votes('node', $nid, 'vote3', NULL);
$vote_3 = $vote_3['average']['value'];
$vote_4 = fivestar_get_votes('node', $nid, 'vote4', NULL);
$vote_4 = $vote_4['average']['value'];
$formula_2 = ($vote_1+$vote_2+$vote_3+$vote_4)/10;
$result = @$formula_1 < @$formula_2 ? -1 : @$formula_1 > @$formula_2;

return  @
$result;
?>