Error message

You need to log in or create an account to access this page.

Problem/Motivation

When using TFA 8.x-1.12 alongside Encrypt 8.x-3.3 on PHP 8.0+, a PHP Fatal error is thrown during config import (and anywhere Drupal loads the plugin registry):

PHP Fatal error: Declaration of Drupal\tfa\Plugin\EncryptionMethod\McryptAES128Encryption::checkDependencies(?string $text = null, ?string $key = null) must be compatible with
  Drupal\encrypt\EncryptionMethodInterface::checkDependencies($text = null, $key = null) in .../tfa/src/Plugin/EncryptionMethod/McryptAES128Encryption.php on line 150

Encrypt 8.x-3.3 added #[\SensitiveParameter] attributes to EncryptionMethodInterface::checkDependencies() while leaving the parameters untyped:

public function checkDependencies(#[\SensitiveParameter] $text = NULL, #[\SensitiveParameter] $key = NULL);

McryptAES128Encryption::checkDependencies() declares ?string type hints, which narrows the accepted types relative to what the interface declares. In PHP 8.0+, an implementing class cannot restrict
parameter types beyond the interface definition.

Steps to reproduce

  1. Install TFA 8.x-1.12 and Encrypt 8.x-3.3 on PHP 8.0+.
  2. Run drush cim or visit any page that triggers plugin autoloading.

Proposed resolution

Remove the ?string type hints from McryptAES128Encryption::checkDependencies() so the signature matches the interface:

public function checkDependencies($text = NULL, $key = NULL) {

Remaining tasks

  • Review and commit patch.

User interface changes

None.

API changes

None.

Data model changes

None.

Comments

scotwith1t created an issue. See original summary.

scotwith1t’s picture

Issue summary: View changes
cmlara’s picture

Status: Active » Postponed (maintainer needs more info)

https://git.drupalcode.org/project/tfa/-/blob/8.x-1.12/src/Plugin/Encryp... does not appear to have a narrowing typehint present.

Are you patching the module during install?

Note:
Please use MR’s in the future, patch files are deprecated on D.O. and are never needed now that all projects have migrated to GitLab.

cmlara’s picture

There are notes that #3496146: Implicitly marking parameter as nullable is deprecated in PHP8.4 may have been incorrectly added similar to its work in progress patch.

I suspect the reporter is utilizing that patch.

ts.ag’s picture

I had the same issue. I can confirm that this was introduced by MR 116 from #3496146: Implicitly marking parameter as nullable is deprecated in PHP8.4 and repatching with the updated MR (or path file from #37) solves this issue.

ts.ag’s picture

Status: Postponed (maintainer needs more info) » Closed (duplicate)

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.