LengthException
PHPERRORCommonValidation

Length of an argument is invalid

Quick Answer

Validate string/array lengths before passing them to functions; throw LengthException for length constraint violations.

What this means

Thrown when the length of an argument is invalid — e.g., a string too short or too long for the operation.

Why it happens
  1. 1Password shorter than minimum required length
  2. 2Payload exceeds maximum allowed byte size

Fix

Length validation

Length validation
function hashPassword(string $raw): string {
    if (strlen($raw) < 8) {
        throw new \LengthException("Password must be at least 8 characters");
    }
    return password_hash($raw, PASSWORD_BCRYPT);
}

Why this works

Early length check provides a user-friendly error before bcrypt rejects the input.

Code examples
Catch in validatorphp
try {
    $hash = hashPassword($input);
} catch (\LengthException $e) {
    return ['error' => $e->getMessage()];
}

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All PHP errors