warning: array_merge_recursive()

huyl - April 30, 2006 - 07:57
Project:Drupal
Version:5.1
Component:node system
Category:bug report
Priority:normal
Assigned:chx
Status:closed
Description

system:FC5
PHP:5.1.2

error:"warning: array_merge_recursive() [function.array-merge-recursive]: Argument #2 is not an array in /var/www/html/web47/modules/node.module on line 1605"

error path:"?q=node/8888/edit"

#1

huyl - April 30, 2006 - 07:59
Status:active» patch (code needs review)

fix node.module on line 1605 to:
"$form = array_merge_recursive($form, array(node_invoke($node, 'form')));"

#2

killes@www.drop.org - April 30, 2006 - 07:59
Status:patch (code needs review)» active

which node type does the node 8888 have?

#3

huyl - May 1, 2006 - 02:21

It's a sample number.

#4

huyl - May 1, 2006 - 03:07

This node type is "aggregator2-item",create by aggregator2 modules at 4.6.X.
yes,"page" and "blog" type no this warning.

#5

asimmonds - May 1, 2006 - 06:14

Most 4.6 modules will not work with 4.7. Try using the CVS version of the aggregator2 module, which looks like it has been updated somewhat for 4.7. This module has not been branched for 4.7 yet, so it could be a little unstable.

#6

Gerhard Killesreiter - May 1, 2006 - 09:56

please move this to aggregator2.module, it seems to be broken.

#7

huyl - May 1, 2006 - 11:49

I agree,but it's better if can take node system more strong.

#8

chx - May 1, 2006 - 11:52
Assigned to:huyl» chx
Status:active» won't fix

I will relentless reject any proposals to make core more bloated to somewhat resist against broken modulen. Nah. Fix your code and leave core as it is.

#9

adrinux - May 4, 2006 - 15:54
Version:4.7.0-rc4» 4.7.0

It's probably worth mentioning I also just got this error. This resulted from trying to edit old blog posts that were created using the blog module whilst the blog module was disabled. Once I enabled the old blog module the error disappeared, and I was able to edit the posts.

So this is basically a configuration error, not a bug as such, and should be easily corrected - as long as the module used to create the content is updated to the current Drupal version!

I'll be moving the problem content into 'story' nodes before disabling blog module again.

#10

kyanos - June 20, 2006 - 14:55

the same problem when i try to make my oun node
at the end of hook_form i used

$output = drupal_get_form('myclient', $form);
return $output;

#11

z.stolar - January 31, 2007 - 09:08
Version:4.7.0» 5.1
Priority:normal» critical
Status:won't fix» active

I just got this error with Drupal 5, and I see the code has not changed in Drupal 5.1 .
The problem occures when a module tries to add a content-type, but it does'nt use hook_form. The error is generated by the function array_merge_recursive, which expects to recieve a list of arrays.
If a certain module defines a content-type, but does not add anything special to its form, then node_invoke does not return anything, and the function breaks. The solution for this issue could be to return an empty array, by default:

<?php
function node_invoke(&$node, $hook, $a2 = NULL, $a3 = NULL, $a4 = NULL) {
  if (
node_hook($node, $hook)) {
   
$module = node_get_types('module', $node);
    if (
$module == 'node') {
     
$module = 'node_content'; // Avoid function name collisions.
   
}
   
$function = $module .'_'. $hook;
    return (
$function($node, $a2, $a3, $a4));
  }
 
# return an empty array, so the calling function won't break:
 
else return array();
}
?>

This is classes critical, because while it might be not the ideal Drupal way, it's not unresonable for a module to add a content-type with no customed form fields (e.g. only a title and a body).

However, there seem to be another problem because, although the form has default values (has_title=>true for example), they don't render for module provided content-types, but that's a story for another issue.

#12

chx - February 23, 2007 - 02:08
Status:active» patch (reviewed & tested by the community)

Ladies and gentlemen, behold this issue! See the first reports which is "This is broken" without offering too much information (a reasonable assumption was that they returned strings) vs "this is how to reproduce and that's why it's broken". The first resulted in 'go away', the second? A patch. Similar constructs can be found in node_load.

AttachmentSize
node_66.patch813 bytes

#13

BioALIEN - February 24, 2007 - 00:55
Status:patch (reviewed & tested by the community)» patch (code needs review)

chx, while I agree with you - the patch does need some review first before its RTBC ;)

#14

z.stolar - February 24, 2007 - 12:29

Can you be a bit more descriptive? Did you find any faults in it, ways to improve it?

#15

pwolanin - February 25, 2007 - 23:19

Does it pass the E_ALL test?

Maybe the patch should be like:

-  $form = array_merge_recursive($form, node_invoke($node, 'form', $form_values));
+  $extra = node_invoke($node, 'form', $form_values);
+  if (is_array($extra)) {
+    $form = array_merge_recursive($form, $extra);
+  }

#16

pwolanin - February 25, 2007 - 23:33
Priority:critical» normal

Since it's an uncommon case (other than the obvious case of disabling the module as mentioned above), i don't think it's critical.

#17

pwolanin - June 23, 2007 - 16:34
Status:patch (code needs review)» fixed

the patch in #12 seems to have already been applied to HEAD and 5.x, perhaps as part of another patch?

#18

Anonymous - July 7, 2007 - 16:45
Status:fixed» closed
 
 

Drupal is a registered trademark of Dries Buytaert.