Problem/Motivation
Deprecated function: Creation of dynamic property Drupal\tfa\Plugin\Tfa\TfaTotp::$isValid is deprecated in Drupal\tfa\Plugin\Tfa\TfaTotp->validate() (line 318 of modules/contrib/tfa/src/Plugin/Tfa/TfaTotp.php).
In PHP 8.2 and later, setting a value to an undeclared class property is deprecated, and emits a deprecation notice the first time the property is set during the lifetime of the application execution.
Proposed resolution
Add property to TfaBasePlugin class.
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | 3371146-8.patch | 1.88 KB | leo liao |
Issue fork tfa-3371146
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:
- 3371146-deprecated-function-creation
changes, plain diff MR !27
Comments
Comment #3
markdorisonComment #4
barry_fisher commentedHi Mark,
Patch is good and applies cleanly. It's a simple and logical fix, so hopefully this will get accepted by the maintainer.
Thanks!
Comment #5
barry_fisher commentedComment #6
jcnventuraIt fixes the problem, but this is not the correct way to fix it.
The isValid property is only ever used inside the protected validate() function in the TfaRecoveryCode, TfaHotp and TfaTotp plugins, and can be trivially simplified by the direct return of the boolean value instead of the assignment to the dynamic property followed by the return, or by an assignment to a function-scope variable (i.e. $is_valid instead of $this->isValid).
I think we can all agree that promoting an internal temporary value of the validate() function to be a property of the plugin base class is not the best way to solve this.
Comment #7
markdorisonI was just assuming that the implementation was intentional, but I am happy to make the change as suggested!
Comment #8
leo liao commentedWe will use this patch in drupal 10 until it is officially released.
Comment #10
jcnventuraComment #13
holo96 commentedCan we get this in next release?
Comment #14
apotek commentedUnfortunately, this did not get ported to the 8x-1.7 release and there is no stable 2 release even a year after this was merged. So while this is closed, it isn't really "fixed" for any sites which require stable releases.
Is there a plan to make a 2.x release? As more and more people update to PHP 8.2/8.3 (Acquia is moving everyone onto those versions now), this issue will only get more widespread.
Comment #15
rupertj commented@apotek This issue isn't present in the 8.x-1.x branch, so there's nothing to port. You can find the roadmap for a 2.x release here: https://www.drupal.org/project/tfa/issues/3374845