Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid deprecated marking a parameter as nullable in PHP 8.4 #663

Closed
BrookeDot opened this issue Feb 13, 2025 · 3 comments
Closed

Avoid deprecated marking a parameter as nullable in PHP 8.4 #663

BrookeDot opened this issue Feb 13, 2025 · 3 comments

Comments

@BrookeDot
Copy link
Contributor

Describe the bug

PHP 8.4 deprecated marking a parameter as nullable. For sites running Two Factor a PHP error shows up in the logs:

u2flib_server\Error::__construct(): Implicitly marking parameter $previous as nullable is deprecated, the explicit nullable type must be used instead

Stacktrace

    wp-content/plugins/two-factor/includes/Yubico/U2F.php:504
    Two_Factor_FIDO_U2F->__construct()
    wp-content/plugins/two-factor/providers/class-two-factor-provider.php:28
    Two_Factor_Provider::get_instance()
    wp-content/plugins/two-factor/class-two-factor-core.php:291
    Two_Factor_Core::get_providers()
    wp-includes/class-wp-hook.php:324
    do_action('init')
    wp-settings.php:704

Steps to Reproduce

  1. Install PHP 8.4, Two Factor and optionally Query Monitor but ensure that logging is enabled
  2. Notice the warning in the logs

Screenshots, screen recording, code snippet

No response

Environment information

PHP 8.4.2
WordPress 6.7.2

Please confirm that you have searched existing issues in this repository.

Yes

Please confirm that you have tested with all plugins deactivated except Two-Factor.

Yes

@BrookeDot
Copy link
Contributor Author

I can open a PR but think we need to update line 504 to:

    public function __construct($message, $code, $previous = null) {

Otherwise if we can bump the PHP version:

    public function __construct($message, $code, \Exception|null $previous = null) {

Both fix the problem with PHP 8.4 so looking for input on the best way forward here.

Line with warning:https://github.com/WordPress/two-factor/blob/master/includes/Yubico/U2F.php#L504

@kasparsd
Copy link
Collaborator

Fixed in #664.

@BrookeDot
Copy link
Contributor Author

@felipeelia pointed out when working on the same problem for ElasticPress (10up/ElasticPress#4086) that we can use ? which is supported in PHP 7.1 so I went with that here. Thanks for the quick merge @kasparsd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants