{"id":"a96db52e1e475077","repo":"laravel/framework","slug":"configuration-value-for-key-s-must-be-an-intege","errorCode":null,"errorMessage":"Configuration value for key [%s] must be an integer, %s given.","messagePattern":"Configuration value for key \\[(.+?)\\] must be an integer, (.+?) given\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Config/Repository.php","lineNumber":117,"sourceCode":"\n        return $value;\n    }\n\n    /**\n     * Get the specified integer configuration value.\n     *\n     * @param  string  $key\n     * @param  (\\Closure():(int|null))|int|null  $default\n     * @return int\n     *\n     * @throws \\InvalidArgumentException\n     */\n    public function integer(string $key, $default = null): int\n    {\n        $value = $this->get($key, $default);\n\n        if (! is_int($value)) {\n            throw new InvalidArgumentException(\n                sprintf('Configuration value for key [%s] must be an integer, %s given.', $key, gettype($value))\n            );\n        }\n\n        return $value;\n    }\n\n    /**\n     * Get the specified float configuration value.\n     *\n     * @param  string  $key\n     * @param  (\\Closure():(float|null))|float|null  $default\n     * @return float\n     *\n     * @throws \\InvalidArgumentException\n     */\n    public function float(string $key, $default = null): float\n    {","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/laravel/framework/blob/bd6b5437e6ad87bb49f9b426724f07a9f64e9683/src/Illuminate/Config/Repository.php#L99-L135","documentation":"Thrown by Repository::integer() (src/Illuminate/Config/Repository.php:117) when the resolved config value is not a PHP int. The method uses is_int() (strict), so a numeric string coming from getenv/.env will fail. It is a fast-fail guard ensuring callers that asked for an integer-typed config value actually get one instead of silently receiving a string.","triggerScenarios":"Calling config()->integer('app.pageSize') or Config::get(...) wrapped via the integer() accessor when the stored value is a string like \"20\", a float, null (no default given), bool, or array. Also triggered by passing a non-int default (e.g. integer('k', \"0\")).","commonSituations":"Env values are always strings in PHP, so integer('app.foo') backed by env('APP_FOO') almost always fails unless env was cast via env('APP_FOO', 0) with an integer default and envvar not set, or via (int) casts in config files. New in Laravel (added alongside typed accessors), so code migrated from get() to integer() commonly trips this.","solutions":["Cast the value in the config file: return (int) env('APP_FOO', 20); so the stored value is a real int.","Provide an integer default at call site: config()->integer('app.pageSize', 20).","If the value is legitimately string-ish, use string() and cast in the consumer: (int) config()->string('app.pageSize').","Verify the key actually resolves — a missing key with no default yields null and fails the is_int check."],"exampleFix":"// before\n// config/app.php -> 'pageSize' => env('APP_PAGE_SIZE'),\n$size = config()->integer('app.pageSize');\n\n// after\n// config/app.php -> 'pageSize' => (int) env('APP_PAGE_SIZE', 20),\n$size = config()->integer('app.pageSize', 20);","handlingStrategy":"validation","validationCode":"$v = config('app.pageSize');\nif (! is_int($v)) {\n    // fix the config source or coerce before calling integer()\n}","typeGuard":"function isIntConfig(\\Illuminate\\Config\\Repository $c, string $key): bool\n{\n    return is_int($c->get($key));\n}","tryCatchPattern":"try {\n    $size = config()->integer('app.pageSize', 20);\n} catch (\\InvalidArgumentException $e) {\n    $size = 20; // safe fallback\n    logger()->warning($e->getMessage());\n}","preventionTips":["Always cast env-backed values in config files: (int) env('KEY', default).","Provide integer defaults when calling integer().","Centralize config accessors and unit-test them with sample .env values."],"tags":["config","type-coercion","env","laravel"],"analyzedSha":"bd6b5437e6ad87bb49f9b426724f07a9f64e9683","analyzedAt":"2026-08-06T00:28:32.783Z","schemaVersion":2}