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
- Install TFA 8.x-1.12 and Encrypt 8.x-3.3 on PHP 8.0+.
- Run
drush cimor 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.
| Comment | File | Size | Author |
|---|
Comments
Comment #2
scotwith1tComment #3
cmlarahttps://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.
Comment #4
cmlaraThere 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.
Comment #5
ts.ag commentedI 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.
Comment #6
ts.ag commented