backdrop / backdrop-issues

Issue tracker for Backdrop core.
144 stars 39 forks source link

Warning: uasort() expects parameter 1 to be array, null given in node_view_multiple() #3628

Closed klonos closed 5 years ago

klonos commented 5 years ago

This is the same as https://www.drupal.org/project/drupal/issues/2684337

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).

...

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

PR: https://github.com/backdrop/backdrop/pull/2556

klonos commented 5 years ago

...adding milestone candidate tag for 1.12.6

herbdool commented 5 years ago

This fix got an RTBC for D7 (it's currently stuck waiting for a check if it's a problem in d8 and a backport which seems to be where issues go to die). So I think it's ok here.

quicksketch commented 5 years ago

Looks great. It's always a good idea to declare the array before appending items. Thanks @klonos and @herbdool! Merged https://github.com/backdrop/backdrop/pull/2556 into 1.x and 1.12.x.

drupol commented 5 years ago

Amazing :heart: