I'm using Drupal 4.7.3 running on PHP5.1 / MySQL 4.1 / IIS5.0

I installed a fresh Drupal 4.7.3 and then enable the node_import module. Everything seems to be working fine until I import the CSV file. An error was displayed which looked like:

warning: array_merge() [function.array-merge]: Argument #2 is not an array in c:\Inetpub\wwwroot\Stage\test\drupalnew\modules\node_import\node_import.module on line 609.

Is there anyway to solve this?

Comments

jamesJonas’s picture

Same problem. I have previously successfuly used this module using a similiar import cvs.

Drupal 4.7.4
Mysql 5.0.22
FC6
PHP 5.1.6
node_import.module - MAIN and 4.6 - Where is 4.7?

array_merge() [function.array-merge]: Argument #1 is not an array in /var/www/html/drupal/modules/node_import/node_import.module on line 609.

Thanks,

jamesJonas’s picture

This is a php 5 issue. It seems the array_merge() function has stronger type casting. This means you have to be sure you are passing the variable as an array. I fixed this by explicitly casting the variable as an array by placing (array) in front of the variable. This is a hack as the variable should have been casted originally as an array. Here is the repaired code:

$errors = array_merge((array)$errors, (array)$function($node, $preview > 0));

James

Robrecht Jacques’s picture

Status: Active » Fixed

$errors is cast as array (see line 569), however the output of the function is not, so I've added a (array) in front of that.

Fixed (node_import.module version 1.47) - reopen this issue if it is not.

jamesJonas’s picture

I assume that this means the correct version is:

$errors = array_merge((array)$errors, $function($node, $preview > 0));

Correct? james

Robrecht Jacques’s picture

Status: Fixed » Active

Hmm, no, I think

$errors = array_merge($errors, (array)$function($node, $preview > 0));

as the error reported was with argument #2. That was the way I fixed it.

But now I see that the error you, gogman, reported is about argument #1. Strange, as $errors = array(); appears a couple of lines above it.

In any case it can't hurt to add it before both (and unfortunately I don't have a php5 handy to test).

Let me know where (array) must be added.

jamesJonas’s picture

This is how I had implemented it in my code:

$errors = array_merge((array)$errors, (array)$function($node, $preview > 0));

The larger question is if $errors or $function are suppossed to be arrays. Here is the php manual page with a warning.

http://www.php.net/array_merge

"The behavior of array_merge() was modified in PHP 5. Unlike PHP 4, array_merge() now only accepts parameters of type array. However, you can use typecasting to merge other types."

<?php
$beginning = 'foo';
$end = array(1 => 'bar');
$result = array_merge((array)$beginning, (array)$end);
print_r($result);
?> 

It was after reading this example that I decided to cast both variables. This was also why I asked an explicit question concerning Arg #1 versus Arg 2, since I was confused by your statement. My current recommendation is to cast both variables. I ran 70k node inserts using this modification. The more elegant solution is to set the variables as arrays earlier in the code, but since this is a common issue for several modules I felt a more direct appoach was called for.

Robrecht Jacques’s picture

Status: Active » Fixed

Fixed (added the cast to $errors too).

Anonymous’s picture

Status: Fixed » Closed (fixed)