Skip to content

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

@netosts

Description

@netosts

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. 🚀

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions