femanager icon indicating copy to clipboard operation
femanager copied to clipboard

TypeError: User registration > method_exists(): Argument #1 ($object_or_class) must be of type object|string, null given

Open BokuNoMaxi opened this issue 1 year ago • 0 comments

We are using femanage version 7.1 and got following error when a user wants to register:

method_exists(): Argument #1 ($object_or_class) must be of type object|string, null given

Core: Exception handler (WEB): Uncaught TYPO3 Exception: method_exists(): Argument #1 ($object_or_class) must be of type object|string, null given | TypeError thrown in file /html/typo3/public/typo3conf/ext/femanager/Classes/Domain/Repository/UserRepository.php in line 143

Reason is a TypeError in the function because the parameter $user is null per default, but the function method_exists expects a string or an object:

public function checkUniquePage($field, $value, User $user = null)
    {
        $query = $this->createQuery();
        $query->getQuerySettings()->setIgnoreEnableFields(true);

        $and = [
            $query->equals($field, $value),
            $query->equals('deleted', 0)
        ];
        if (method_exists($user, 'getUid')) {
            $and[] = $query->logicalNot($query->equals('uid', (int)$user->getUid()));
        }
        $constraint = $query->logicalAnd($and);

        $query->matching($constraint);

        /** @var User $user */
        $user = $query->execute()->getFirst();

        return $user;
    }

easy solution is to to check if $user is set in the condition and the TypeError is gone: if ($user && method_exists($user, 'getUid'))

I don't know how you like or handle stuff like that, but I could add a PullRequest too 😄

BokuNoMaxi avatar Mar 21 '23 13:03 BokuNoMaxi