Returning a boolean from a uasort comparison function is deprecated in PHP 8 and produces a warning on the group type permissions form. Switching the comparison to use the spaceship operator fixes this.
Symptoms
(for people can find this issue more easily)
Deprecated function: uasort(): Returning bool from comparison function is deprecated, return an integer less than, equal to, or greater than zero in Drupal\group\Access\GroupPermissionHandler->sortPermissions() (line 268 of modules/contrib/group/src/Access/GroupPermissionHandler.php).
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | uasort-comparison-3210808-2.patch | 1.02 KB | davisben |
Issue fork group-3210808
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
davisbenHere is a patch.
Comment #3
tim.anderson commentedThis may be superseded by https://www.drupal.org/project/group/issues/3254097. That work as committed to 2.0.x, and the issue says it may be backported, but the patch applies cleanly to 1.4. Identical solution though. Thanks for providing this several months ago!
Comment #4
chi commentedThe patch fixed the notice for me.
Comment #5
carroll_webprog commentedThis patch#2 also worked for me thank you!
Comment #6
pcate commentedPatch #2 worked for me as well.
Comment #7
bessonweb commentedThis patch work good for me too !
Comment #8
dpi⬆️
Comment #9
heddn+1 on RTBC.
Comment #10
jimmynash commentedPatch in #2 works for me as well.
Comment #11
jan-e commentedThe patch at #2 applied without problems on Group 8.x-1.5
Comment #12
sachbearbeiter commented+1 on RTBC
Comment #13
scotwith1tAnother +1 here. Been using this patch in multiple builds in prod for a while :)
Comment #14
austin_brian commentedThe patch at #2 applied without problems on Group 8.x-1.5
+1 RTBC
Comment #16
donquixote commentedComment #17
donquixote commentedPatch looks good!
Just for the fun of it, the following would be a shorter version of the compare function and uasort() call:
But let's go ahead with the current patch, anything else could be a follow-up.
Comment #18
Yuri commentedPatch #2 makes my views blocks disappear that display group content with some group content relations. Did not dig deep in this yet.
Drupal 9.4.10, PHP8.1.14, Using installation profile social-11.7.0-rc1 that uses Group 8.x-1.5
Comment #19
joe_carvajalPatch #2 works perfectly for me with these versions:
- PHP 8.1.18
- Drupal 9.5.9
- Group 8.x-1.5
But reading the docs I decided to move to Group 2.1, as recommended. By the way, the GroupPermissionHandler.php file has the patch applied there.
Comment #20
jan-e commentedFixed in Group 8.x-1.6
Comment #21
dpi@20
This is not the case for the 1.x series.
3.x was resolved in #3254097: Group's use of uasort returns booleans, switch to spaceship operator., though that issue should have been marked as a dupe, as this issue covers multiple branches and predates it.
Comment #22
masoom2206 commentedPatch in #2 works for me as well. But it not for drupal/group (1.6.0).
So here is the patch for drupal/group (1.6.0)
I have added new patch here: https://www.drupal.org/project/group/issues/3210808#comment-15246841
Comment #23
zcht commentedThe patch #2 also works excellently under Group 1.6.
@masoom2206 What makes you think it doesn't work? Your patch is, by the way, a 1:1 copy, no difference to patch #2.
Comment #24
masoom2206 commented@zcht, The issue is related to line number not match in drupal/group (1.6.0).
sorry for wrong patch uploaded. I have attached here the updated patch for drupal/group (1.6.0).
Comment #25
masoom2206 commentedComment #26
jordik commentedThe patch from #3254097: Group's use of uasort returns booleans, switch to spaceship operator. applies perfectly to Group 1.6 and was already committed to 3.x.
Comment #27
magdalenaa67 commented#24 /uasort-comparison-3210808-2.patch worked for me in Group 1.6, Core 9.5.11 - Thank you!