laravel/framework · error · InvalidArgumentException

Configuration value for key

Error message

Configuration value for key [%s] must be a float, %s given.

What it means

Thrown by Config\Repository::float(string $key) when the stored value is not a float. The check is is_float($value); note that an int value (e.g. 5) is NOT a float in PHP's strict sense and will fail this check, as will numeric strings, bools, and null. InvalidArgumentException reports the key and the actual type.

Solutions

  1. Cast the value to float in the config file: (float) env('PAYMENT_FEE', 0.0).
  2. Provide a float default: Config::float('payment.fee', 0.0).
  3. Ensure the stored literal is a float (e.g. 5.0, not 5) when you control the config.

Example fix

// before
// config: 'fee' => env('PAYMENT_FEE', 5),  // int default
$fee = Config::float('payment.fee');
// after
// config: 'fee' => (float) env('PAYMENT_FEE', 5.0),
$fee = Config::float('payment.fee', 5.0);
Defensive patterns

Strategy: type-guard

Validate before calling

$value = Config::get('payment.fee');
if (! is_float($value)) {
    throw new \InvalidArgumentException('payment.fee must be float');
}

Type guard

function configIsFloat(string $key): bool {
    return is_float(Config::get($key));
}

Try / catch

try {
    $fee = Config::float('payment.fee');
} catch (\InvalidArgumentException $e) {
    $fee = 0.0; // safe default
}

Prevention

When it happens

Trigger: Config::float('payment.fee') where the config stores 5 (int), '5.0' (string), or null; reading an env-backed value without a float cast.

Common situations: Config file stores a literal integer where a float was expected; env returns a string; missing key with no float default. The int-vs-float strictness is the most common surprise.

Related errors


AI-assisted analysis of laravel/framework@e0f6eb3518 (2026-08-11). Data as JSON: /api/errors/771101f1e289f224. Report an issue: GitHub.

Appendix: source

Thrown at src/Illuminate/Config/Repository.php:139

        return $value;
    }

    /**
     * Get the specified float configuration value.
     *
     * @param  string  $key
     * @param  (\Closure():(float|null))|float|null  $default
     * @return float
     *
     * @throws \InvalidArgumentException
     */
    public function float(string $key, $default = null): float
    {
        $value = $this->get($key, $default);

        if (! is_float($value)) {
            throw new InvalidArgumentException(
                sprintf('Configuration value for key [%s] must be a float, %s given.', $key, gettype($value))
            );
        }

        return $value;
    }

    /**
     * Get the specified boolean configuration value.
     *
     * @param  string  $key
     * @param  (\Closure():(bool|null))|bool|null  $default
     * @return bool
     *
     * @throws \InvalidArgumentException
     */
    public function boolean(string $key, $default = null): bool
    {

View on GitHub (pinned to e0f6eb3518)