Skip to content

⚠️ PHP 8.2+ Deprecation Warning: Implicitly nullable callable in getByClaimName() #2286

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

Open
netosts opened this issue Apr 3, 2025 · 1 comment

Comments

@netosts
Copy link

netosts commented Apr 3, 2025

Description:
In PHP 8.2 and later, passing a nullable parameter without explicitly marking it as ?callable is deprecated. The Tymon\JWTAuth\Claims\Collection::getByClaimName() method currently defines $callback as callable $callback = null, which triggers a deprecation warning.

Error Message:

PHP Deprecated:  Tymon\JWTAuth\Claims\Collection::getByClaimName(): Implicitly marking parameter $callback as nullable is deprecated, the explicit nullable type must be used instead in /app/vendor/tymon/jwt-auth/src/Claims/Collection.php on line 38

Affected Code:

/**
 * Get a Claim instance by its unique name.
 *
 * @param  string  $name
 * @param  callable  $callback
 * @param  mixed  $default
 * @return \Tymon\JWTAuth\Claims\Claim
 */
public function getByClaimName($name, callable $callback = null, $default = null)
{
    return $this->filter(function (Claim $claim) use ($name) {
        return $claim->getName() === $name;
    })->first($callback, $default);
}

Suggested Fix:
Modify the function signature to explicitly mark $callback as nullable:

public function getByClaimName($name, ?callable $callback = null, $default = null)

Steps to Reproduce:

  1. Use PHP 8.2 or later.
  2. Install tymon/jwt-auth and attempt to call getByClaimName().
  3. Observe the deprecation warning in the logs.

Environment Details:

  • PHP Version: ^8.2
  • Laravel Version: ^11.0
  • jwt-auth Version: ^2.1

Impact:
This deprecation warning will become a fatal error in future PHP versions, making it necessary to update the function signature.

Would appreciate a fix for this issue! Thanks for maintaining this library. 🚀

@kravchenko-a
Copy link

This has already been fixed in version 2.2.0
https://github.com/tymondesigns/jwt-auth/blob/2.2.0/src/Claims/Collection.php#L38

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