When enabling both metatags and token I get a lot of warning on every page :
Warning : uasort(): Array was modified by the user comparison function dans Drupal\token\Token->getInfo() (ligne 56 de /home/site/web/modules/contrib/token/src/Token.php).
I thought it was a token related issue but by digging I saw this issue : https://www.drupal.org/node/1163976 : and the answer gave by Dave Reid was :
That would point to some module not providing proper token info via hook_token_info(). You don't have any other contrib modules enabled?
Am I the only one to get this warning ?
Comments
Comment #2
kgaut commentedJust to be clear, every thing seems to work properly. Except that my syslog get polluted ;)
Comment #3
mr.baileysWhile Metatag uses tokens, it does not provide any new tokens. Are you sure the issue is caused by the Metatag module (for example, are you still getting these errors when Metatag is disabled but Token remains enabled?)
Comment #4
kgaut commentedHi,
Uninstalling metatag module remove the error.
I didn't put anything specific on my metatag configuration, even with the standard configuration fresh after a new metatag installation, the error is back.
Thanks for your help.
Comment #5
mr.baileysUnable to reproduce with D8.1.x, Metatag 8.x-1.x-dev, Token 8.x-1.0-alpha2...
Can you list the versions you are using, along with your PHP version? Can you also show what's in your Token::sortTokens()-function (there is a known PHP bug where, if you use any debug-statement in that function, it gives the warning you're referring too even though the arrays have not been altered, see https://bugs.php.net/bug.php?id=50688)
Additionally, can you dump the contents of $token_info just prior to sorting in Token::getInfo():56 to see if it contains any clues?
Comment #6
kgaut commentedtoken 8.x-1.0-alpha2
metatag 8.x-1.0-beta4
drupal 8.0.2
PHP 5.6.11
Method Token::getInfo() :
Comment #7
damienmckennaThanks for helping to track down the root cause of the bug, mr.baileys.
Kgaut: It seems like the bug is triggered by a problem with the tokens, which is why mr.baileys asked you to provide a dump of the $token_info. Looking at the sortTokens() method in the Token module, it uses strnatcmp() to compare the 'name' values of each token, so maybe one of the tokens doesn't have a 'name' value? You might try changing that method to the following:
That'll print out the token that's causing the problem.
Comment #8
kgaut commentedI dig a bit and it seems that every tokens has a name.
here's the full trace :
note : 'bet, pronos, mespronos, pronostics' are the keywords I set.
Comment #9
jose reyero commentedThe problem is these names are not strings anymore, but TranslatableMarkup and related objects...
I've tried converting them to string before using strnatcmp but no luck either, so I'm trying this quick and dirty workaround, note the '@':
Comment #10
jose reyero commentedHowever the solution to this bug would be not doing such ordering in the first place. TranslatableMarkup objects cannot be ordered without they being converted to strings and that order doesn't make sense anyway because it applies only for a specific language.
I we want to display tokens in order we should be ordering them when being displayed -maybe an after render hook- for a specific language, not here.
Moving this to Token module which is where it belongs and tagging it as Bug.
I've filed a similar issue for Search API, https://www.drupal.org/node/2758321
Comment #11
berdirI think this can be closed as duplicate of #2671060: Use SortArray::stableUasort instead uasort to prevent warnings (Array was modified by the user comparison function) then ?
Comment #12
lucasgrecco commentedThere is a problem with uasort function.
Here is the ticket https://bugs.php.net/bug.php?id=50688
Comment #13
matthb commentedIm getting this on any php >=5.6 version, extremely annoying.
@lucasgrecco is absolutely right, but I wonder if its worth detecting version and silencing the warning when the uasort is called?
Comment #14
berdirOn Drupal 8? We don't use that function anymore, you need to figure out which module is causing it for you and report a bug there.
Comment #15
phenom commentedHi,
on Drupal 8.2.7 I found this on
Drupal\Core\Plugin\DefaultLazyPluginCollection->sort() (line 90 of core/lib/Drupal/Core/Plugin/DefaultLazyPluginCollection.php).and also on
Warning: uasort(): Array was modified by the user comparison function in Drupal\shortcut\Entity\ShortcutSet->getShortcuts() (line 120 of core/modules/shortcut/src/Entity/ShortcutSet.php).for info I've just enabled Webprofiler. I didn't have any error before.
Cheers.
Comment #16
BartGysens commentedHey,
I just activated Devel Kint and Web Profiler and also get this error. I have Token enabled.
Uninstalling Web Profiler resolved the error.
Backtrace: