ellite/Wallos · error · InvalidArgumentException

Parameter " " does not exist

Error message

Parameter "%s" does not exist

What it means

getParameter() looks up a parameter among the OTP object's set parameters. When the requested parameter key was never set, it throws this InvalidArgumentException instead of returning null, forcing callers to treat missing parameters as programming errors.

Solutions

  1. Set the parameter via setParameter() or the factory method (e.g. createFromSecret) before reading it
  2. Check hasParameter('x') before calling getParameter('x')
  3. Use getParameters() to inspect all currently set keys

Example fix

// before
$digits = $otp->getParameter('digits'); // throws if unset
// after
if ($otp->hasParameter('digits')) {
    $digits = $otp->getParameter('digits');
}
Defensive patterns

Strategy: try-catch

Validate before calling

if (!$otp->hasParameter('digits')) {
    throw new \LogicException('digits must be configured first');
}

Type guard

function paramOrNull($otp, string $key): mixed {
    return $otp->hasParameter($key) ? $otp->getParameter($key) : null;
}

Try / catch

try {
    $value = $otp->getParameter('period');
} catch (\InvalidArgumentException $e) {
    $value = 30; // default period
}

Prevention

When it happens

Trigger: Calling getParameter('period')/getParameter('algorithm')/etc. on an OTP object where that key was never passed to createFromSecret/createFromDigits or setParameter; getSecret/getDigits/getDigest all funnel through this method.

Common situations: Building an OTP object step by step and reading a parameter before setting it; copy-pasting code between HOTP and TOTP where only one has 'period'; deserializing a partial parameter array.

Related errors


AI-assisted analysis of ellite/Wallos@52820e87ca (2026-09-13). Data as JSON: /api/errors/b21e4bb90d406742. Report an issue: GitHub.

Appendix: source

Thrown at libs/OTPHP/ParameterTrait.php:112

    {
        $value = $this->getParameter('algorithm');
        (is_string($value) && $value !== '') || throw new InvalidArgumentException('Invalid "algorithm" parameter.');

        return $value;
    }

    public function hasParameter(string $parameter): bool
    {
        return array_key_exists($parameter, $this->parameters);
    }

    public function getParameter(string $parameter): mixed
    {
        if ($this->hasParameter($parameter)) {
            return $this->getParameters()[$parameter];
        }

        throw new InvalidArgumentException(sprintf('Parameter "%s" does not exist', $parameter));
    }

    public function setParameter(string $parameter, mixed $value): void
    {
        $map = $this->getParameterMap();

        if (array_key_exists($parameter, $map) === true) {
            $callback = $map[$parameter];
            $value = $callback($value);
        }

        if (property_exists($this, $parameter)) {
            $this->{$parameter} = $value;
        } else {
            $this->parameters[$parameter] = $value;
        }
    }

View on GitHub (pinned to 52820e87ca)