A PHP Warning is triggered if an empty array is passed to node_view_multiple().

Documentation says that node_view_multiple() accepts "An array of nodes as returned by node_load_multiple()."
So, node_view_multiple() should be able to use any node_load_multiple() result without any kind of
conditional statements... But node_load_multiple() could return an empty array, which is not correctly used in node_view_multiple(), resulting with the following PHP Warning :

Warning: uasort() expects parameter 1 to be array, null given in node_view_multiple() (line 2679 of /modules/node/node.module).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

geoffray created an issue. See original summary.

peter.walter’s picture

Your patch looks sensible, but please can you explain how to reproduce the error.

geoffray’s picture

Here is how to reproduce the error :

// loading node ids... ie from EntityFieldQuery, could result of an empty array
$nids = array();

$nodes = node_load_multiple($nids); // receive an empty array, and return and empty array without complaining
$view = node_view_multiple($nodes); // E_WARNING
geoffray’s picture

Status: Active » Needs review
jweowu’s picture

Status: Needs review » Reviewed & tested by the community

Confirming the bug and the solution.

We could alternatively bail out early when $nodes is empty, but as it is very little processing actually happens in this scenario with the current patch, so I'm in favour of just committing it.

Pol’s picture

Issue tags: +Drupal 7.60 target

Hello,

Thanks for the bug report and patch.

I confirm the bug and the patch is fixing the issue.

joseph.olstad’s picture

Issue tags: -Drupal 7.60 target +Drupal 7.61 target

Bumping to 7.61, this didn't make it into 7.60

joseph.olstad’s picture

joseph.olstad’s picture

Fabianx’s picture

Status: Reviewed & tested by the community » Needs review

We need to check if this is present in D8 first

jweowu’s picture

Ugh. That policy simply shouldn't apply across the border between Drupal 7 and Drupal 8. The two codebases bear almost no resemblance to one another.

Pol’s picture

Hi,

It's not a matter of codebase, we know that 7 and 8 are completely different.
It's about features. Even if it's a kind of bug fix, we must first see if it needs to be fixed in 8 then backport to 7.

Pol’s picture

Issue tags: -Drupal 7.64 target +Drupal 7.65 target, +Already In D8
Pol’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Drupal 7.65 target +Drupal 7.67 target

This issue cannot be reproduced in D8, it can go in D7.

Fabianx’s picture

Issue tags: -Needs framework manager review +Pending Drupal 7 commit

  • Fabianx committed c8a2662 on 7.x authored by Pol
    Issue #2684337 by geoffray, Pol, jweowu, Fabianx: Warning: uasort()...
Pol’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: -DX, -Already In D8, -Pending Drupal 7 commit

Fixed! Thanks all.

Status: Fixed » Closed (fixed)

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