There are several places where a required function parameter follows a parameter with a default value. This raises a deprecation notice in PHP 8.0. These can be fixed by removing the default values preceding parameters without them.

Issue fork entity-3206793

Command icon 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

Liam Morland created an issue. See original summary.

damienmckenna’s picture

Running tests on Metatag results in the following:

fail: [PHP Deprecated] Line 229 of sites/all/modules/entity/modules/callbacks.inc:
 Required parameter $options follows optional parameter $data

fail: [PHP Deprecated] Line 229 of sites/all/modules/entity/modules/callbacks.inc:
 Required parameter $name follows optional parameter $data

fail: [PHP Deprecated] Line 259 of sites/all/modules/entity/modules/callbacks.inc:
 Required parameter $options follows optional parameter $data

fail: [PHP Deprecated] Line 259 of sites/all/modules/entity/modules/callbacks.inc:
 Required parameter $name follows optional parameter $data

fail: [PHP Deprecated] Line 837 of sites/all/modules/entity/modules/callbacks.inc:
 Required parameter $entity_type follows optional parameter $file

fail: [PHP Deprecated] Line 857 of sites/all/modules/entity/modules/callbacks.inc:
 Required parameter $entity_type follows optional parameter $entity

fail: [PHP Deprecated] Line 865 of sites/all/modules/entity/modules/callbacks.inc:
 Required parameter $entity_type follows optional parameter $values

fail: [PHP Deprecated] Line 971 of sites/all/modules/entity/modules/callbacks.inc:
 Required parameter $entity_type follows optional parameter $view_mode
damienmckenna’s picture

Title: Remove required parameter following optional parameter » Remove required parameter following optional parameter (PHP 8.0)
damienmckenna’s picture

The same errors also occur with the Date module.

damienmckenna’s picture

Status: Active » Needs review
StatusFileSize
new3.09 KB

A possible solution.

liam morland’s picture

Thanks for the patch.

The change to entity_metadata_system_get_page_properties() adds an array type declaration. That parameter it not actually used, so this function could be called without an array. I recommend leaving it to a separate issue to add type declarations.

Some of the changes add a default value to currently-required parameters instead of removing the defaults. This is probably harmless, but also probably useless. Any current calls to the function need to provide all the parameters anyway. Unless there is a clear use case for these functions with more optional parameters, I recommend fixing the issue by removing the default values.

damienmckenna’s picture

StatusFileSize
new4.07 KB

So something more like this?

liam morland’s picture

No change is needed to entity_metadata_user_access() and entity_metadata_taxonomy_access(). The others looks fine. There is nothing wrong with having default values. There just can't be default values on parameters that precede a parameter without a default.

liam morland’s picture

tr’s picture

Priority: Normal » Major
Related issues: +#3209769: [meta] Make D7 rules compatible with PHP 8.0/8.1

The same errors affect Rules. They will affect ALL modules that have Entity API as a dependency, but Rules is one of the big ones.

Because Entity API is used on about 70% of all Drupal sites according to the usage statistics, Drupal can't really claim to be "PHP 8.0 compatible" until Entity API and a few other essential modules are made to work with PHP 8.0.

Bumping priority to "Major" because this affects so many sites.

liam morland’s picture

Created merge request with the patch in #7 minus the changes to entity_metadata_user_access() and entity_metadata_taxonomy_access().

tr’s picture

Status: Needs review » Reviewed & tested by the community

This fixes the problems in a backwards-compatible way. And it's a surprisingly small patch that will have a big impact.

  • TR committed 67bc94c on 7.x-1.x authored by Liam Morland
    Issue #3206793 by Liam Morland, DamienMcKenna: Remove required parameter...
tr’s picture

Status: Reviewed & tested by the community » Fixed

Merged. Thanks. I plan to release a new 7.x-1.10 branch including this fix, but I first need to triage the issue queue and determine what other small fixes should be included. As 7.x-1.x is going to be minimally maintained until D7 EOL, I don't anticipate including any new features or any potentially disruptive changes at all.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

joseph.olstad’s picture

@TR, great work and thanks very much in advance! We might as well tag and release? This will greatly assist the move to support php 8.0

tr’s picture

@joseph.olstad: I opened an issue for the new release: #3221001: Plan for release of 7.x-1.10

If you can, please go through the issue queue and help me identify some issues that can be committed and/or finished off quickly so we can get them into the new release. Post your findings in #3221001: Plan for release of 7.x-1.10, and hopefully I can get those committed and the release made within the next few weeks.

tr’s picture

This patch missed fixing the functions in entity.features.inc. See #3222090: Remove required parameter following optional parameter in entity.features.inc (PHP 8.0) for a follow-up issue.

entity.features.inc was missed because it is not used by the Entity API tests, so testing against PHP 8.0 did not reveal the problems.