* warning: array_merge() [function.array-merge]: Argument #1 is not an array in /media/wd500/www/devroots/d6-matadortravel-com/sites/all/modules/location/location.module on line 1409.

Error appears twice when viewing a user's page, with content profile, APK installed on drupal 6.9

This is the referenced code...

**
 * Returns an empty location object based on the given settings.
 */
function location_empty_location($settings) {
  $defaults = location_invoke_locationapi($location, 'defaults');
  if (isset($settings['form']['fields'])) {
    foreach ($settings['form']['fields'] as $k => $v) {
      $defaults[$k] = array_merge($defaults[$k], $v); //line 1409
    }
  }

...

So it looks like location_invoke_locationapi is screwing up, giving a non array (or nothing at all)...

Comments

orces’s picture

Same problem

warning: array_merge() [function.array-merge]: Argument #1 is not an array in xxx/sites/all/modules/location/location.module on line 1409.
warning: array_merge() [function.array-merge]: Argument #1 is not an array in xxx/sites/all/modules/location/location.module on line 1409.

bdragon’s picture

Status: Active » Closed (duplicate)
pinxi’s picture

Status: Closed (duplicate) » Active

Re-opening this request.

This is for 5.x-3.0:
#346988: [master] Argument #1 is not an array

I am using:

version = "6.x-3.0"
core = "6.x"
project = "location"
datestamp = "1229117725"

I have the same issue as described above. Two array errors on Edit:

* warning: array_merge() [function.array-merge]: Argument #1 is not an array in /drupal-6.10/sites/all/modules/location/location.module on line 1409.
* warning: array_merge() [function.array-merge]: Argument #1 is not an array in /drupal-6.10/sites/all/modules/location/location.module on line 1409.

-pinxi

yesct’s picture

marked #411982: warning: array_merge() a duplicate of this issue

karens’s picture

Priority: Normal » Critical

See:

**
* Returns an empty location object based on the given settings.
*/
function location_empty_location($settings) {
  $defaults = location_invoke_locationapi($location, 'defaults');
  if (isset($settings['form']['fields'])) {
    foreach ($settings['form']['fields'] as $k => $v) {
      $defaults[$k] = array_merge($defaults[$k], $v); //line 1409
    }
  }

...

Note that $location (which is never defined) is used in location_invoke_location(). I don't know if that was supposed to be location_invoke_locationapi($settings, 'defaults'); or something else.

karens’s picture

Status: Active » Needs review
StatusFileSize
new952 bytes

$location is defined further down, I'm guessing it just needs to be moved up before location_invoke_locationapi(). Patch attached.

jeffschuler’s picture

StatusFileSize
new922 bytes

bump.

same thing for 5.x-3.x-dev...

bricef’s picture

I had the same problem due to a malformed settings. I corrected the problem like this :

function location_empty_location($settings) {
  $location = array();	
  $defaults = location_invoke_locationapi($location, 'defaults');
  if (isset($settings['form']['fields'])) {
    foreach ($settings['form']['fields'] as $k => $v) {
    	if (! is_null ($defaults[$k])){
    		$defaults[$k] = array_merge($defaults[$k], $v);
    	}
    }
  }
...
jefftrnr’s picture

I still get the error, unless I change the same bit of code to:

function location_empty_location($settings) {
  $location = array();
  $defaults = location_invoke_locationapi($location, 'defaults');
  if (!is_array($defaults['locpick'])) $defaults['locpick'] = array();
  if (isset($settings['form']['fields'])) {
    foreach ($settings['form']['fields'] as $k => $v) {
      $defaults[$k] = array_merge($defaults[$k], $v);
    }
  }
...

"locpick" seems to be missing it's defaults settings.

sirkitree’s picture

subscribe - this seems to be causing errors with submission too.

sirkitree’s picture

Just needs to be a bit more robust I think... try

diff --git a/html/sites/all/modules/location/location.module b/html/sites/all/modules/location/location.module
index 705f206..ac911b9 100644
--- a/html/sites/all/modules/location/location.module
+++ b/html/sites/all/modules/location/location.module
@@ -1405,9 +1405,11 @@ function location_is_empty($location, &$filled) {
 function location_empty_location($settings) {
   $location = array();
   $defaults = location_invoke_locationapi($location, 'defaults');
-  if (!is_array($defaults['locpick'])) $defaults['locpick'] = array();
   if (isset($settings['form']['fields'])) {
     foreach ($settings['form']['fields'] as $k => $v) {
+      if (!isset($defaults[$k])) {
+        $defaults[$k] = array();
+      }
       $defaults[$k] = array_merge($defaults[$k], $v);
     }
   }

*EDIT*
I'll also note that this error was completely making so that my node, with a location_cck field, would not be created at all. So in my case it was not just 'lockpick' that was not set, but cck-something-or_other as well. Using this fixed that and would fix any key that happens to be within $settings['form']['fields'] and not within $defaults.

yesct’s picture

Priority: Critical » Minor
Status: Needs review » Postponed (maintainer needs more info)

I think this is just a problem for some people, not all. Any idea what combination of situations causes the problem? Can you make a new test site using the new dev release, with just location, and document the steps you go through to reproduce the error?

todd zebert’s picture

same issue. subscribe. going to try Dev version.

yesct’s picture

Status: Postponed (maintainer needs more info) » Needs review
StatusFileSize
new495 bytes

I haven't taken my own advice and done a simple blank test site to recreate the error (yet). But I did start getting the error when I upgraded to the new dev, for example on my add user form (where I have cck locations in the content profiles). Attached the patch suggested in #12 by sirkitree (it got rid of the errors for me)

--- location.module.orig        2010-04-09 01:11:14.211671813 -0400
+++ location.module     2010-04-09 01:11:45.161606063 -0400
@@ -1406,6 +1406,9 @@ function location_empty_location($settin
   $defaults = location_invoke_locationapi($location, 'defaults');
   if (isset($settings['form']['fields'])) {
     foreach ($settings['form']['fields'] as $k => $v) {
+      if (!isset($defaults[$k])) {
+        $defaults[$k] = array();
+      }
       $defaults[$k] = array_merge($defaults[$k], $v);
     }
   }
yesct’s picture

steps to reproduce:
clean site 6.16 with modules:
Administration menu 6.x-1.5
Content Construction Kit (CCK) 6.x-2.6
Includes: Content, Fieldgroup, Option Widgets, Text
Location 6.x-3.0
Includes: Location, Location CCK
Poormanscron 6.x-2.2
Includes: Poormanscron
Views 6.x-2.10
Includes: Views, Views UI

Add a new content type, add a cck location field, create a node of that content type and should get the error.

yesct’s picture

Issue tags: +location bdragon check

tagging

yesct’s picture

marked #662250: warning: array_merge() as a duplicate of this issue

modulist’s picture

FIX: Try upgrading to version 6.x-3.1-rc1 or better

I ran into this issue migrating from one server to another. The original server was running version 6.x-3.1-rc1, while the destination server was running the older 6.x-3.0.

Not only were we getting the line 1409 error, but no one was able to update or add any nodes in certain content types that used Location CCK fields.

An upgrade to 6.x-3.1-rc1 resolved these issues.

rooby’s picture

Version: 6.x-3.0 » 6.x-3.x-dev

This is already fixed in 6.x-3.x-dev. I'm not sure when but the current code for that part (#15) is now:

<?php
  if (isset($settings['form']['fields'])) {
    foreach ($settings['form']['fields'] as $k => $v) {
      if (isset($defaults[$k])) {
        $defaults[$k] = array_merge($defaults[$k], $v);
      }
    }
  }
?>

Can you confirm the problem is fixed in the latest dev?

ankur’s picture

Status: Needs review » Closed (fixed)

This looks fixed to me.