The following shows up in my admin logs whenever a page that includes a search box is loaded:

array_merge() [function.array-merge]: Argument #2 is not an array in [...snip...]/modules/search.module on line 934

My line 934 reads:

$form = array_merge($form, module_invoke($type, 'search', 'form', $keys));

May be related to recent changes for the new Form API. The actual search box works normally when a search is performed. I believe the error possibly relates to displaying the search form.

Tested using CVS as of Nov. 3, 2005 w/Apache 2.0.55, PHP 5.0.5, MySQL 5.0.5 and IE 6.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

chx’s picture

form API is not responsible for bird flu and black death. Nor it is responsible for every bug. I am fed up with blaming that change for everything.

module_invoke may return NULL and I guess that's the problem here. Save its' return value to a var and if it's an array then merge.

Thomas Sewell’s picture

Amusing comment. I take it you're getting a bit touchy? :)

I actually meant that I thought it might have been caused by changes in the search.module meant to comply with the new form API, not any problem with the form API itself. Seemed reasonable at the time, since it was part of a new style Form API form definition.

After some additional sluething through the various versions, while it is in a form section, it was added right after the form API changes in 1.137, for http://drupal.org/node/28159, Advanced Search Features.

See also http://cvs.drupal.org/viewcvs/drupal/drupal/modules/search.module?r1=1.1...

I'll try to avoid offending anyone by guessing and try to never use "may be" in the future.

I'll see if I can figure out a patch that fixes this bug, now that you've pointed me in the right direction. I'm an experienced programmer, but my PHP experience is extremely light (read, virtually non-existant) and I only heard about Drupal a couple of weeks ago, so I'm just trying to help test the latest versions of Drupal as I learn and report new bugs as I run across them.

Thanks for the work on the Form API, BTW.

Thomas Sewell’s picture

Status: Active » Needs review
FileSize
667 bytes

Patch attached.

Thomas Sewell’s picture

Assigned: Unassigned » Thomas Sewell
Status: Needs review » Active

After a little module grep'ing found the same "potential" issue in a few other places. I'll attach similar patches for filter.module, node.module and an updated one for search.module in a bit.

Thomas Sewell’s picture

Status: Active » Needs review
FileSize
563 bytes

Attaching patches for checking to see if the results of module_invoke is an array or not before attempting to use it in an array_merge for filter.module, node.module and search.module.

Tested the patches as much as I am able, please review.

First Patch attached

Thomas Sewell’s picture

FileSize
553 bytes

Second patch, for filter.module.

Thomas Sewell’s picture

FileSize
1.25 KB

Third patch of three, this one updated for search.module.

Thomas Sewell’s picture

Assigned: Thomas Sewell » Unassigned
Status: Needs review » Reviewed & tested by the community
Steven’s picture

Status: Reviewed & tested by the community » Needs work

module_invoke_all() already ensures its return value is an array. Only the locations with module_invoke() need to be changed.

Also, please post a single patch.

Thomas Sewell’s picture

Status: Needs work » Reviewed & tested by the community
FileSize
1.19 KB

Patch consolidated and revised to check only module_invoke and not module_invoke_all.

Dries’s picture

If the invoked module returns an incorrect return value, it's perfectly valid to generate an error. This patch seems to hide errors in other modules?

Thomas Sewell’s picture

If the hook being called using module_invoke has no values to return in a particular case, what should it return instead?

Currently, when there is no valid result data to return, it appears to return a Null, leading to this error. Presumably (haven't dug through every possible call), an invoked module function can perform it's expected task and sometimes return data and sometimes have no data to return.

In that case, returning a Null would not be an error, but will cause an error if it isn't handled by the function using module_invoke.

So that's the case for error handling it by the calling function, because only the calling function presumably knows if it requires data from the module_invoke call, rather than simply wanting to add information to an array from the module_invoke if there is additional information present. That's my current assumption from my admittedly slim overall knowledge of the system.

If those assumptions are not correct, then I can see where either:

1. Module_invoke() itself needs to add an else argument and return something not Null if the result of the invoked function is Null, in which case functions using module_invoke should presumably be updated to handle whatever that alternate return value would be.
or
2. All invokable hooks need to be reviewed to ensure there is no case where they will not return valid data of some sort.

I'd personally lean towards neither 1 nor 2, because of the complications in changing expected return values for functions using module_invoke from what they currently expect as always being valid data or a Null, to always returning valid data.

Existing functions (pre this patch) already use the method in the patch to check for a Null and only merge the value returned if it's not null. See http://drupaldocs.org/api/head/function/search_form for an existing example.

Steven’s picture

Status: Reviewed & tested by the community » Fixed

Sorry: I committed this patch, but forgot to change the status.

The tricky bit is that both are instances of multi-op hooks, where we cannot check for the presence of any particular sub-hook. In both these cases, a module should imo be able to return NULL.

Anonymous’s picture

Status: Fixed » Closed (fixed)