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
fix node.module on line 1605 to:
"$form = array_merge_recursive($form, array(node_invoke($node, 'form')));"
#2
which node type does the node 8888 have?
#3
It's a sample number.
#4
This node type is "aggregator2-item",create by aggregator2 modules at 4.6.X.
yes,"page" and "blog" type no this warning.
#5
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
please move this to aggregator2.module, it seems to be broken.
#7
I agree,but it's better if can take node system more strong.
#8
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
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
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
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:
<?phpfunction 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
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.
#13
chx, while I agree with you - the patch does need some review first before its RTBC ;)
#14
Can you be a bit more descriptive? Did you find any faults in it, ways to improve it?
#15
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
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
the patch in #12 seems to have already been applied to HEAD and 5.x, perhaps as part of another patch?
#18