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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

shkiper created an issue. See original summary.

awasson’s picture

I 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

awasson’s picture

Status: Needs review » Reviewed & tested by the community

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

awasson’s picture

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

euk’s picture

The patch in #4 introduces a breaking change to API - function arguments order is changed.
Stick to the original patch.

euk’s picture

Status: Reviewed & tested by the community » Needs review
awasson’s picture

Excellent 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:

if(!isset($dropbox)) {
  $dropbox=FALSE;
}

Cheers,
Andrew

euk’s picture

According to PHP documentation - NULL and unset variables are evaluated as FALSE when used in expressions.
PHP Booleans

awasson’s picture

Excellent.

I've been using the patch from @shkiper on several sites running PHP 8.1 without any issues.

Cheers,
Andrew

undersound3’s picture

Issue tags: +PHP 8.0
joseph.olstad’s picture

Status: Needs review » Reviewed & tested by the community