There's something odd going on with array_diff_assoc. From php.net:

This function only checks one dimension of a n-dimensional array.

Comments

Found it: http://drupal.org/node/1525176#comment-6012112
It's related to PHP 5.4

Issue tags:+php5.4

confirmed with php5.4

Status:Active» Postponed

Postponed on what core will be doing. Updated Compatibility Issues section of features page to mention it.

Status:Postponed» Active

Mine is D7.14

Status:Active» Postponed

Postponed to see how core is handling this general problem with using that function.

So we can only wait? can't fix this by features itsself?

Warning: Illegal string offset 'format' in views_object->unpack_translatable() (line 330 of /opt/development/yourhelps/sites/all/modules/views/includes/base.inc).
Warning: Illegal string offset 'format' in views_object->unpack_translatable() (line 330 of /opt/development/yourhelps/sites/all/modules/views/includes/base.inc).
Notice: Array to string conversion in features_export_prepare() (line 190 of /opt/development/yourhelps/sites/all/modules/features/features.export.inc).
Notice: Array to string conversion in features_export_prepare() (line 190 of /opt/development/yourhelps/sites/all/modules/features/features.export.inc).
Notice: Array to string conversion in EntityAPIControllerExportable->applyConditions() (line 624 of /opt/development/yourhelps/sites/all/modules/entity/includes/entity.controller.inc).
Notice: Array to string conversion in EntityAPIControllerExportable->applyConditions() (line 624 of /opt/development/yourhelps/sites/all/modules/entity/includes/entity.controller.inc).
Notice: Array to string conversion in EntityAPIControllerExportable->applyConditions() (line 624 of /opt/development/yourhelps/sites/all/modules/entity/includes/entity.controller.inc).
Warning: Illegal string offset 'format' in views_object->unpack_translatable() (lin..........................

Status:Postponed» Active

What exactly is it that is being waited upon? Aside from the issue already mentioned, there were (at least) two other issues before 7.14 with similar problems. In both cases, the code got a slight re-factoring, and the problem went away.

See #1338282: Fix php notice in menu_link_save() and #1414412: Skip #conjunction key in __clone() method of core/includes/database/query.inc.

PHP hasn't actually changed anything, it just makes it more clear that a cast occurs, and warns that it may have un-intended side-effects. There will be no "one-off" solution that can be applied to every instance of this, but rather each issue needs its own fix.

You can't use array_diff_assoc with a multi-dimensional array. Doing so has always been a bug, but PHP didn't make any fuss about until 5.4. PHP will step "down" once and expect to find strings, if somethine else is found, PHP casts, and we get warnings, which is a good thing.

Features simply needs to either never pass arrays within in arrays to array_diff_assoc, or use a different function to achieve whatever test is causing the error.

I was able to solve this issue by using a custom function to handle multi dimensional arrays.

function array_diff_assoc2_deep($array1, $array2) {
    $ret = array();
    foreach ($array1 as $k => $v) {
        if (!isset($array2[$k])) $ret[$k] = $v;
        else if (is_array($v) && is_array($array2[$k])) $ret[$k] = array_diff_assoc2_deep($v, $array2[$k]);
        else if ((string)$v != (string)$array2[$k]) $ret[$k] = $v;
    }
    return $ret;
}

Issue tags:-php5.4+PHP 5.4

Change to the tag 'php5.4' to the tag used in Drupal core 'PHP 5.4'.

Priority:Minor» Normal

This is not a minor problem. This actually prevents successfully comparing two multidimensional arrays. The arrays are cast to the string "Array" so this means that the arrays will always be considered equal, even if they are not.

I think the solution is to add a array_diff_assoc_recursive() function to Drupal core, as proposed in #1850798: Add a recursive version of array_diff_assoc(). In the meanwhile we can include our own features_array_diff_assoc_recursive() function and use that.

Version:7.x-1.0-rc2» 7.x-1.x-dev
Priority:Normal» Minor
Status:Active» Needs review
StatusFileSize
new2.1 KB

Here's a patch. It is derived from a comment at the documentation page of array_diff_assoc(): http://php.net/manual/en/function.array-diff-assoc.php#73972

Patch #11 works for me using:

Drupal 7.14
PHP 5.4.9
features-7.x-2.0-beta1

Patch #11 works for me as well.

  • Drupal 7.18
  • PHP 5.4.6-1ubuntu1.1 (cli)
  • Features 7.x-2.0-beta1

Status:Needs review» Reviewed & tested by the community

Patch #11 works and looks nice and clean.

Yep, confirming this is RTBC. The patch in #11 works well. Also applies to 7.x-2.x with some offset, works fine.

#11 Works for me. RTBC

#11 seems to work fine.

Just a note, #1850798: Add a recursive version of array_diff_assoc() has been committed to 8.x and is in the process of being backported to 7.x. If the patch in #11 would be committed we would need a followup issue to replace this with the core version when #1850798 lands.

can this one commit to dev version ? since this is not in the latest version I guess. Thanks.

Version:7.x-1.x-dev» 7.x-2.x-dev
Status:Reviewed & tested by the community» Fixed

In the future, please follow the procedures given in [#707484] for creating a proper patch via git.

But I have committed this patch to 95c0b0a in the 2.x-dev branch.

I follow the rival 'git format-patch' procedure from the Advanced patch contributor guide :)

I'm curious what trouble did you have with this? This patch format should be compatible with patch -p1, git apply and git am, and has the advantage that it provides a commit message and author metadata, making it really easy to apply the patch with git am.

Hmm, thanks for the link. Had not seen that yep. I usually apply patches with "git apply" rather than "patch -p1" so it was just a minor annoyance. If this new way represents the direction of the community, then I'll stick with it. Didn't actually know about "git am" so I learned something new. I actually use the dreditor chrome plugin to review patches and generate the commit message. I prefer this because it gives everybody who contributed to the thread mention.

#11 Worked. Thanks.

@mpotter keep in mind that git am is equivalent to setting git commit --author, which is great because it actually shows up on d.o profiles.

Automatically closed -- issue fixed for 2 weeks with no activity.