Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
Comment | File | Size | Author |
---|---|---|---|
#10 | array-merge2.patch | 1.19 KB | Thomas Sewell |
#7 | search-array-merge.patch | 1.25 KB | Thomas Sewell |
#6 | filter-array-merge.patch | 553 bytes | Thomas Sewell |
#5 | node-array-merge.patch | 563 bytes | Thomas Sewell |
#3 | array-merge.patch | 667 bytes | Thomas Sewell |
Comments
Comment #1
chx CreditAttribution: chx commentedform 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.
Comment #2
Thomas Sewell CreditAttribution: Thomas Sewell commentedAmusing 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.
Comment #3
Thomas Sewell CreditAttribution: Thomas Sewell commentedPatch attached.
Comment #4
Thomas Sewell CreditAttribution: Thomas Sewell commentedAfter 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.
Comment #5
Thomas Sewell CreditAttribution: Thomas Sewell commentedAttaching 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
Comment #6
Thomas Sewell CreditAttribution: Thomas Sewell commentedSecond patch, for filter.module.
Comment #7
Thomas Sewell CreditAttribution: Thomas Sewell commentedThird patch of three, this one updated for search.module.
Comment #8
Thomas Sewell CreditAttribution: Thomas Sewell commentedComment #9
Steven CreditAttribution: Steven commentedmodule_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.
Comment #10
Thomas Sewell CreditAttribution: Thomas Sewell commentedPatch consolidated and revised to check only module_invoke and not module_invoke_all.
Comment #11
Dries CreditAttribution: Dries commentedIf 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?
Comment #12
Thomas Sewell CreditAttribution: Thomas Sewell commentedIf 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.
Comment #13
Steven CreditAttribution: Steven commentedSorry: 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.
Comment #14
(not verified) CreditAttribution: commented