PHP Strict Standards: Only variables should be assigned by reference

admin2025-06-06  0

Here's the code in question. It started looking like this:

$comments_by_type = &separate_comments(get_comments('status=approve&post_id=' . $id));  
return count($comments_by_type['comment']);

I removed the & signs per other posts I have seen but it didn't help.

$comments_by_type = separate_comments(get_comments('status=approve post_id=' . $id));
return count($comments_by_type['comment']);

Here's the code in question. It started looking like this:

$comments_by_type = &separate_comments(get_comments('status=approve&post_id=' . $id));  
return count($comments_by_type['comment']);

I removed the & signs per other posts I have seen but it didn't help.

$comments_by_type = separate_comments(get_comments('status=approve post_id=' . $id));
return count($comments_by_type['comment']);
Share Improve this question edited Nov 1, 2018 at 18:42 Will B. 1136 bronze badges asked Nov 1, 2018 at 16:56 MBensonMBenson 11 silver badge2 bronze badges 3
  • the arguments for separate_comments are being passed by-reference as function separate_comments(&$comments). You would need to assign get_comments to a variable. $comments = get_comments('status=approve&post_id=' . $id); Then separate_comments($comments); – Will B. Commented Nov 1, 2018 at 17:25
  • I tried your suggestion: $comments_by_type = (get_comments('status=approve&post_id=' . $id)); separate_comments($comments); return count($comments_by_type['comment']); it didn't work.....thanks for trying. – MBenson Commented Nov 1, 2018 at 18:51
  • You passed the wrong variable name to separate_comments as you never defined $comments, please see my answer. – Will B. Commented Nov 1, 2018 at 19:11
Add a comment  | 

1 Answer 1

Reset to default 1

The issue is caused by the arguments for separate_comments being passed by-reference. Source: function separate_comments(&$comments). This means passing a function as an argument is restricted.

To resolve the issue you need to assign the get_comments function results to a variable.

$comments = get_comments('status=approve&post_id=' . $id);
$comments_by_type = separate_comments($comments);
return count($comments_by_type['comment']);
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749213085a317310.html

最新回复(0)