{"record":{"id":"03a8e9da11d41a28","repo":"cakephp/cakephp","slug":"invalid-time-parameter-ensure-your-time-value-can-be-parsed","errorCode":null,"errorMessage":"Invalid time parameter. Ensure your time value can be parsed by strtotime","messagePattern":"Invalid time parameter\\. Ensure your time value can be parsed by strtotime","errorType":"validation","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Http/Response.php","lineNumber":597,"sourceCode":"    {\n        return $this->withHeader('Expires', 'Mon, 26 Jul 1997 05:00:00 GMT')\n            ->withHeader('Last-Modified', CakeDateTime::parse(time())->toRfc7231String())\n            ->withHeader('Cache-Control', 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0');\n    }\n\n    /**\n     * Create a new instance with the headers to enable client caching.\n     *\n     * @param string|int $since a valid time since the response text has not been modified\n     * @param string|int $time a valid time for cache expiry\n     * @return static\n     */\n    public function withCache(string|int $since, string|int $time = '+1 day'): static\n    {\n        if (!is_int($time)) {\n            $time = strtotime($time);\n            if ($time === false) {\n                throw new InvalidArgumentException(\n                    'Invalid time parameter. Ensure your time value can be parsed by strtotime',\n                );\n            }\n        }\n\n        return $this->withHeader('Date', CakeDateTime::parse(time())->toRfc7231String())\n            ->withModified($since)\n            ->withExpires($time)\n            ->withSharable(true)\n            ->withMaxAge($time - time());\n    }\n\n    /**\n     * Create a new instance with the public/private Cache-Control directive set.\n     *\n     * @param bool $public If set to true, the Cache-Control header will be set as public\n     *   if set to false, the response will be set to private.\n     * @param int|null $time time in seconds after which the response should no longer be considered fresh.","sourceCodeStart":579,"sourceCodeEnd":615,"githubUrl":"https://github.com/cakephp/cakephp/blob/1128eba9b09f1946df684811350e26f2cef68fac/src/Http/Response.php#L579-L615","documentation":"withCache() accepts a string|int for the `$time` parameter used to compute the Expires header. When a string is passed, it is parsed with strtotime(); if parsing fails, this InvalidArgumentException is thrown because the library cannot derive a valid expiration timestamp.","triggerScenarios":"Calling $response->withCache($since, $time) where $time is a non-integer string that strtotime() cannot parse, e.g. '+1 dayz', 'tomorrow at 25pm', '', or a locale-formatted date like 'morgen'.","commonSituations":"Hardcoded typo in a relative time expression; passing user-supplied date strings without validation; passing locale-dependent strings in non-English environments where strtotime expects English.","solutions":["Fix the time string so strtotime() can parse it (e.g. '+1 day', '+3600 seconds')","Pass an integer Unix timestamp instead of a string to skip strtotime parsing entirely","Validate the string with strtotime($time) !== false before calling withCache()","Check for typos and locale issues in dynamically built time expressions"],"exampleFix":"// before\n$response = $response->withCache(time(), '+1 dayz');\n// after\n$response = $response->withCache(time(), time() + 86400);","handlingStrategy":"validation","validationCode":"if (!is_int($time) && strtotime($time) === false) {\n    throw new InvalidArgumentException(\"Unparseable time: {$time}\");\n}\n$response = $response->withCache($since, $time);","typeGuard":"function isParseableTime(string|int $time): bool {\n    return is_int($time) || strtotime($time) !== false;\n}","tryCatchPattern":"try {\n    $response = $response->withCache($since, $time);\n} catch (InvalidArgumentException $e) {\n    $response = $response->withCache($since, time() + 86400);\n}","preventionTips":["Prefer integer timestamps over relative time strings","Keep a whitelist of approved relative expressions like '+1 day'","Never pass raw user input as the time parameter"],"tags":["php","datetime","http-cache","invalid-argument"],"backgroundTag":"invalid-date-format","analyzedSha":"1128eba9b09f1946df684811350e26f2cef68fac","analyzedAt":"2026-09-12T12:07:00.388Z","contentChangedAt":"2026-09-12T12:07:00.388Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}