Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
When upgrading to PHP8, I got this warning:
FILE: hierarchical_select/hierarchical_select.module
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 3 WARNINGS AFFECTING 1 LINE
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1388 | WARNING | Declaring a required parameter after an optional one is deprecated since PHP 8.0. Parameter $dropbox is optional, while parameter $module is required.
1388 | WARNING | Declaring a required parameter after an optional one is deprecated since PHP 8.0. Parameter $dropbox is optional, while parameter $params is required.
1388 | WARNING | Declaring a required parameter after an optional one is deprecated since PHP 8.0. Parameter $dropbox is optional, while parameter $save_lineage is required.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Steps to reproduce
Upgrade server to PHP8, then run a drush command and see warning.
Proposed resolution
Update parameters in function declaration.
Comment | File | Size | Author |
---|---|---|---|
hierarchical_select-php8.patch | 773 bytes | shkiper | |
Comments
Comment #2
awasson CreditAttribution: awasson commentedI have the same same problem upgrading to PHP 8.0 and PHP 8.1. It caused AJAX to fail with a 200 response. The problem was occurring with Drupal AJAX as well as Views AJAX to break.
The patch fixed the issue. I'm not sure that there is a downside to it.
Cheers,
Andrew
Comment #3
awasson CreditAttribution: awasson commentedI'm going to go ahead and mark this as Reviewed and Tested. It's been up for 5 months so it's probably been reviewed as much as it will be. I have run it through its paces on my site where I'm using it for selecting Taxonomy terms in a hierarchy.
PHP 7.4 will be unsupported in a month or so and that will force numerous upgrades to PHP 8.1. This bug did nasty things to my site on PHP 8.0/8.1 so I'm sure it will do the same to others that are using it.
Cheers,
Andrew
Comment #4
awasson CreditAttribution: awasson commentedI've done a little further looking into this issue and I've concluded that the problem isn't that the $dropbox variable has a default but that the $dropbox = FALSE variable is in the wrong position in the list of arguments. Since it is an optional argument, PHP 8.1 requires that it be the last argument. I've attached a patch for this and since it doesn't change the code in any practical way, this should be good to go.
Cheers,
Andrew
Comment #5
euk CreditAttribution: euk commentedThe patch in #4 introduces a breaking change to API - function arguments order is changed.
Stick to the original patch.
Comment #6
euk CreditAttribution: euk commentedComment #7
awasson CreditAttribution: awasson commentedExcellent point @euk. I wasn't thinking.
I'll hide #4 so that it doesn't cause any confusion.
I wonder what the downside of not setting $dropbox as false is... I wonder if there should be a statement like:
Cheers,
Andrew
Comment #8
euk CreditAttribution: euk commentedAccording to PHP documentation - NULL and unset variables are evaluated as FALSE when used in expressions.
PHP Booleans
Comment #9
awasson CreditAttribution: awasson commentedExcellent.
I've been using the patch from @shkiper on several sites running PHP 8.1 without any issues.
Cheers,
Andrew
Comment #10
undersound3 CreditAttribution: undersound3 at Finalist commentedComment #11
joseph.olstadRTBC patch #1
https://www.drupal.org/files/issues/2022-04-29/hierarchical_select-php8....