Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
There's something odd going on with array_diff_assoc. From php.net:
This function only checks one dimension of a n-dimensional array.
Comment | File | Size | Author |
---|---|---|---|
#11 | 1588596-11-features-array_diff_assoc_recursive.patch | 2.1 KB | pfrenssen |
Comments
Comment #1
barraponto CreditAttribution: barraponto commentedFound it: http://drupal.org/node/1525176#comment-6012112
It's related to PHP 5.4
Comment #2
rogical CreditAttribution: rogical commentedconfirmed with php5.4
Comment #3
hefox CreditAttribution: hefox commentedPostponed on what core will be doing. Updated Compatibility Issues section of features page to mention it.
Comment #4
rogical CreditAttribution: rogical commentedMine is D7.14
Comment #5
hefox CreditAttribution: hefox commentedPostponed to see how core is handling this general problem with using that function.
Comment #6
rogical CreditAttribution: rogical commentedSo 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..........................
Comment #7
Letharion CreditAttribution: Letharion commentedWhat 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.
Comment #8
achagani CreditAttribution: achagani commentedI was able to solve this issue by using a custom function to handle multi dimensional arrays.
Comment #9
scitoChange to the tag 'php5.4' to the tag used in Drupal core 'PHP 5.4'.
Comment #10
pfrenssenThis 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.
Comment #11
pfrenssenHere'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
Comment #12
waverate CreditAttribution: waverate commentedPatch #11 works for me using:
Comment #13
haxney CreditAttribution: haxney commentedPatch #11 works for me as well.
Comment #14
logaritmisk CreditAttribution: logaritmisk commentedPatch #11 works and looks nice and clean.
Comment #15
fenstratYep, confirming this is RTBC. The patch in #11 works well. Also applies to 7.x-2.x with some offset, works fine.
Comment #16
azinck CreditAttribution: azinck commented#11 Works for me. RTBC
Comment #17
dagomar CreditAttribution: dagomar commented#11 seems to work fine.
Comment #18
pfrenssenJust 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.
Comment #19
windmaomao CreditAttribution: windmaomao commentedcan this one commit to dev version ? since this is not in the latest version I guess. Thanks.
Comment #20
mpotter CreditAttribution: mpotter commentedIn 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.
Comment #21
pfrenssenI 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
andgit am
, and has the advantage that it provides a commit message and author metadata, making it really easy to apply the patch withgit am
.Comment #22
mpotter CreditAttribution: mpotter commentedHmm, 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.
Comment #23
rwoldezghi CreditAttribution: rwoldezghi commented#11 Worked. Thanks.
Comment #24
barraponto CreditAttribution: barraponto commented@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.