Closed (outdated)
Project:
Drupal core
Version:
10.1.x-dev
Component:
shortcut.module
Priority:
Normal
Category:
Bug report
Assigned:
Issue tags:
Reporter:
Created:
11 Sep 2015 at 15:55 UTC
Updated:
26 Jan 2023 at 09:42 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
jibranCan you add steps to reproduce?
We can put @ before usort but we have #1247666: Replace @function calls with try/catch ErrorException blocks to remove all those calls.
Comment #3
lussolucaJust install The Webprofiler module along with the Shortcut module and enable "Errors and warnings" in "Logging and error" (or use settings.local.php). You will see the warning message on every page.
Using a try/catch doesn't work here because there isn't any error, PHP throws a warning because debug_backtrace() changes the reference count and uasort thinks that the array is changed.
Comment #4
chi commentedFaced with the same bug using Debug Bar module. Added @ before uasort as was suggested.
Comment #5
mikey_p commentedLooks good, I didn't have a chance to dig into this, but I figured something odd was going on since I knew D8 wouldn't ship with this kind of warning.
Comment #6
chi commentedI just found exact same fix in getVisibleBlocksPerRegion().
I propose we document it as well.
Comment #7
chi commentedComment #8
xmacinfo*Deleted initial comment*
I first reported a problem with the patch! But to tell the truth, I did not applied it correctly.
I do not see that pesky error any more. :-)
Comment #9
xmacinfoMarking as RTBC.
Feel free to change if you notice something else.
Comment #10
lussoluca+1 for me
Comment #11
Anonymous (not verified) commentedI found the same issue in
\Drupal\Core\Config\Entity\ConfigEntityListBuilder::load()while using webprofiler module.Another potential solution is to use:
Which may be better than suppressing all errors. The bug is unfortunately in PHP itself. It may be worth considering wrapping
uasort()asdrupal_uasort(); then check PHP version and whether or not debugging, to decide if it is necessary to suppress warnings?Comment #12
swentel commentedThere's a meta issue to replace uasort completely, see #2466097: uasort() does NOT preserve sort order, but core assumes so (Element::children, css sort, ...), so this issue might be obsolete.
Also, there's two patches now here, that doesn't really help either to get a commit.
Comment #13
Anonymous (not verified) commentedI personally wouldn't recommend committing uses of
@operators. #2466097 is a separate issue ofuasort()not performing as expected; the suggested solutions would not solve this problem, as they still call PHP'suasort()function without warning suppression.Comment #14
swentel commentedYeah, not to keen on adding @ either in different places with always the same comment then. The other issue can fix its original goal and then maybe use the @ operator there ?
Comment #15
Anonymous (not verified) commentedI've just added a patch to the other ticket that solves the issue raised there, directly with
uasort(), and also solves this one by not using PHP's.https://www.drupal.org/node/2466097#comment-10803028
Comment #17
marcoscanoIn the meantime, a simple workaround for those who are developing with the webprofiler bar and don't want to see these errors in the log:
1) Delete the shortcut links created by default on drupal installation:
/admin/config/user-interface/shortcut/link/1/delete
/admin/config/user-interface/shortcut/link/2/delete
2) Uninstall the "Shortcut" module at /admin/modules/uninstall
After this the errors do not show anymore.
Comment #20
mikey_p commentedComment #21
shaisamuel commentedPatch #20 solve another error, when webprofiler is active:
uasort(): Array was modified by the user comparison function in core/lib/Drupal/Core/Config/Entity/ConfigEntityListBuilder.php on line 24Comment #22
jibranThanks, for the patch and testing the patch.
Comment #23
alexpottHmmm... but once the minimum version is PHP7 then these @'s are more harmful than good since the bug that is causing the problem is fixed in PHP7. There have been safe sort discussions elsewhere but I'm really not sure that just adding @ is the way to go here. When we've hit this before we've converted them to an array_multisort()
Comment #24
chi commentedI believe this is the very case when @ is quite appropriate. We suppress code errors caused by the bug in external code which we cannot fix ourselves. I would also add TODO statements to remove @ when support for PHP 5 is dropped.
Comment #25
jibranLet's use
array_multisorthere as @alexpott suggested.Comment #26
harsha012 commentedAs per #25 i have re-rolled the patch with array_multisort().
Comment #27
harsha012 commentedComment #29
harsha012 commentedComment #30
harsha012 commentedComment #32
ytsurkThe provided patch #26 makes the warning disappear, looks good and uses array_multisort (so not @ anymore).
Testing failed because of missing disk space on jenkins .. so i schedule a retest.
Comment #33
mariacha1 commentedThe patch 2567035-26-usort.patch creates a warning on the /admin/structure/block page:
It also makes placing blocks through the UI result in an "Internal Server Error" from fastcgi.
This is on PHP 7.0.12 and Apache/2.4.23, both installed with Homebrew.
Comment #35
Hamza Bahlaouane commentedWarning: uasort(): Array was modified by the user comparison function in Drupal\Core\Field\FieldTypePluginManager->getSortedDefinitions() (line 98 of core/lib/Drupal/Core/Plugin/CategorizingPluginManagerTrait.php).
Adding @ solved the issue.
Comment #36
darkdimComment #37
darkdimFixed according to http://shout.setfive.com/2013/06/14/symfony2-usort-array-was-modified-by...
Comment #38
darkdimComment #40
darkdimComment #41
darkdimComment #42
mikey_p commentedCould you add a comment about why this code is in place? Might want to include a link back to this issue or the blog post you referenced.
Comment #43
darkdimComment #44
darkdim#mikey_p Thank you!
I added a comment.
Comment #45
darkdimComment #46
darkdimComment #49
gottaknow commentedI have a local Drupal core 8.6.2 with the following modules enabled.
Admin Toolbar 8.x-1.24
Devel 8.x-1.2
Quick Node Clone 8.x-1.11
With Devel and Examples for Developers the site is fine. As soon as I enable webprofiler the site breaks.
I am using Mamp pro 4 with PHP 7.2.1. The only way I get the site back up is uninstalling webprofiler.
drush pm-uninstall webprofilerI am assuming that since I am on 8.6.2 the patches mentioned on this page are in core.
I really would like to use webprofiler. How can I get this to work.
Comment #50
lussolucaNo that patch has never been committed to core, you have to disable the shortcut module to use webprofiler at the moment
Comment #51
bdimaggioWe've been having good luck with #20 through many Drupal 8 installs, so I'm going to update that here with a slight change to allow it to continue applying cleanly to 8.8.x.
Comment #56
ranjith_kumar_k_u commentedComment #57
alexpottIf removing the args works then I think we should consider doing that because it's a more generic fix. A contrib module could cause the same issue and the args are not as important as the stack trace.
Comment #58
xmacinfoComment #61
quietone commentedA related issue was a bugsmash target this week. Both lendude and I discussed it.
We concluded that this can be closed as outdated. The full details are in #2831964-19: Warning: uasort(): Array was modified by the user comparison function in Drupal\Core\Config\Entity\ConfigEntityListBuilder->load().