laravel/framework · error · InvalidArgumentException

Array value for key [ ] must be a float, found.

Error message

Array value for key [%s] must be a float, %s found.

What it means

Thrown by Arr::float() when the resolved value is not a PHP float. Note is_float() is strict: an int 5 is not a float and will throw, unlike filter_var-based paths.

Solutions

  1. Pass a float default: Arr::float($data, 'key', 0.0).
  2. Cast the source to float before lookup: (float) $data['rate'].
  3. Use Arr::get() and cast manually when int values are valid.

Example fix

// before
$rate = Arr::float($config, 'rate'); // int 5 throws
// after
$rate = Arr::float($config, 'rate', 0.0);
Defensive patterns

Strategy: validation

Validate before calling

$raw = Arr::get($data, 'rate');
if (! is_float($raw)) {
    $raw = (float) $raw; // explicit cast if numeric
}
// or guard before calling Arr::float().

Type guard

function isStrictFloat(mixed $value): bool { return is_float($value); }

Try / catch

try {
    $rate = Arr::float($config, 'rate');
} catch (\InvalidArgumentException $e) {
    $rate = 0.0;
}

Prevention

When it happens

Trigger: Calling Arr::float($data, 'key') where the value is an int, non-numeric string, bool, array, or null.

Common situations: JSON config where a rate is encoded as an integer; cache/API payloads with mixed numeric types; missing keys.

Related errors


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

Appendix: source

Thrown at src/Illuminate/Collections/Arr.php:401

                    $result[] = $value;
                }
            }
        }

        return $result;
    }

    /**
     * Get a float item from an array using "dot" notation.
     *
     * @throws \InvalidArgumentException
     */
    public static function float(ArrayAccess|array $array, string|int|null $key, ?float $default = null): float
    {
        $value = Arr::get($array, $key, $default);

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

        return $value;
    }

    /**
     * Remove one or many array items from a given array using "dot" notation.
     *
     * @param  array  $array
     * @param  array|string|int|float  $keys
     * @return void
     */
    public static function forget(&$array, $keys)
    {
        $original = &$array;

View on GitHub (pinned to e0f6eb3518)