Problem/Motivation

Database::startLog() calls Log::findCaller() that calls debug_backtrace() that broke uasort() with

Warning: uasort(): Array was modified by the user comparison function in Drupal\shortcut\Entity\ShortcutSet->getShortcuts() (line 125 of core/modules/shortcut/src/Entity/ShortcutSet.php).

because of this bug: https://bugs.php.net/bug.php?id=50688

Proposed resolution

  1. put a @ before uasort in ShortcutSet::getShortcuts()
  2. use debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS) instead of debug_backtrace() (but then we cannot collect args)

Remaining tasks

Decide which solution is better.

User interface changes

None

API changes

None

Data model changes

With solution 2 we don't collect function args.

Comments

lussoluca created an issue. See original summary.

jibran’s picture

Can 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.

lussoluca’s picture

Just 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.

chi’s picture

Status: Active » Needs review
StatusFileSize
new661 bytes

Faced with the same bug using Debug Bar module. Added @ before uasort as was suggested.

mikey_p’s picture

Status: Needs review » Reviewed & tested by the community

Looks 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.

chi’s picture

Status: Reviewed & tested by the community » Needs work

I just found exact same fix in getVisibleBlocksPerRegion().
I propose we document it as well.

chi’s picture

Status: Needs work » Needs review
StatusFileSize
new801 bytes
xmacinfo’s picture

*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. :-)

xmacinfo’s picture

Status: Needs review » Reviewed & tested by the community

Marking as RTBC.

Feel free to change if you notice something else.

lussoluca’s picture

+1 for me

Anonymous’s picture

StatusFileSize
new656 bytes

I found the same issue in \Drupal\Core\Config\Entity\ConfigEntityListBuilder::load() while using webprofiler module.

Another potential solution is to use:

$error_reporting_level = error_reporting(E_ERROR);
uasort(...);
error_reporting($error_reporting_level);

Which may be better than suppressing all errors. The bug is unfortunately in PHP itself. It may be worth considering wrapping uasort() as drupal_uasort(); then check PHP version and whether or not debugging, to decide if it is necessary to suppress warnings?

swentel’s picture

Status: Reviewed & tested by the community » Needs work
Related issues: +#2466097: uasort() does NOT preserve sort order, but core assumes so (Element::children, css sort, ...)

There'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.

Anonymous’s picture

I personally wouldn't recommend committing uses of @ operators. #2466097 is a separate issue of uasort() not performing as expected; the suggested solutions would not solve this problem, as they still call PHP's uasort() function without warning suppression.

swentel’s picture

Yeah, 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 ?

Anonymous’s picture

I'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

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

marcoscano’s picture

In 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.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

mikey_p’s picture

Status: Needs work » Needs review
StatusFileSize
new1.55 KB
shaisamuel’s picture

Patch #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 24

jibran’s picture

Status: Needs review » Reviewed & tested by the community
Related issues: +#1247666: Replace @function calls with try/catch ErrorException blocks

Thanks, for the patch and testing the patch.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

Hmmm... 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()

chi’s picture

I 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.

jibran’s picture

Let's use array_multisort here as @alexpott suggested.

harsha012’s picture

StatusFileSize
new1.28 KB

As per #25 i have re-rolled the patch with array_multisort().

harsha012’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 26: 2567035-26.patch, failed testing.

harsha012’s picture

StatusFileSize
new1.28 KB
new1.28 KB
harsha012’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 29: 2567035-26-usort.patch, failed testing.

ytsurk’s picture

The 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.

mariacha1’s picture

The patch 2567035-26-usort.patch creates a warning on the /admin/structure/block page:

Warning: array_multisort(): Array sizes are inconsistent in Drupal\Core\Config\Entity\ConfigEntityListBuilder->load() (line 25 of core/lib/Drupal/Core/Config/Entity/ConfigEntityListBuilder.php).

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.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Hamza Bahlaouane’s picture

Warning: 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.

darkdim’s picture

Assigned: Unassigned » darkdim
darkdim’s picture

darkdim’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 37: 2567035-37-usort.patch, failed testing. View results

darkdim’s picture

StatusFileSize
new670 bytes
darkdim’s picture

Status: Needs work » Needs review
mikey_p’s picture

Could 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.

darkdim’s picture

StatusFileSize
new801 bytes
darkdim’s picture

#mikey_p Thank you!
I added a comment.

darkdim’s picture

darkdim’s picture

StatusFileSize
new802 bytes

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

gottaknow’s picture

I 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.

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

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 webprofiler
I 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.

lussoluca’s picture

I am assuming that since I am on 8.6.2 the patches mentioned on this page are in core.

No that patch has never been committed to core, you have to disable the shortcut module to use webprofiler at the moment

bdimaggio’s picture

StatusFileSize
new1.57 KB
new542 bytes

We'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.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev
ranjith_kumar_k_u’s picture

StatusFileSize
new1.56 KB
new608 bytes
alexpott’s picture

If 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.

xmacinfo’s picture

Version: 9.3.x-dev » 9.4.x-dev

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Status: Needs review » Closed (outdated)
Issue tags: +Bug Smash Initiative

A 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().