In some cases I'm getting "Array was modified by the user comparison function" on these lines in token.module:

foreach (array_keys($token_info['tokens']) as $type) {
  uasort($token_info['tokens'][$type], 'token_asort_tokens');

I have only managed to reproduce this while running automated tests on my website's codebase.

One way of consistently reproducing this might be to have a third party module hook implementation not return a name key in the token data. (That's not the case for me though).

If your continuous integration scripts fail when this happens, you might consider suppressing the error like this:

foreach (array_keys($token_info['tokens']) as $type) {
  @uasort($token_info['tokens'][$type], 'token_asort_tokens');

It would be nice to reproduce this and add an automated test just for this purpose, however in the meantime the enclosed patch seems to fix this. If many people are experiencing this issue, I think this change could be introduced to Token with little risk.

#2671060: Use SortArray::stableUasort instead uasort to prevent warnings (Array was modified by the user comparison function)
#2466097: uasort() does NOT preserve sort order, but core assumes so (Element::children, css sort, ...)

Members fund testing for the Drupal project. Drupal Association Learn more


alberto56 created an issue. See original summary.

alberto56’s picture

Here is a a patch.