{"record":{"id":"de986fbd93ab8984","repo":"phalcon/cphalcon","slug":"invalid-modifier-modifier","errorCode":null,"errorMessage":"Invalid modifier: \"{modifier}\"","messagePattern":"Invalid modifier: \"(.+?)\"","errorType":"exception","errorClass":"Phalcon\\Time\\Clock\\Exceptions\\InvalidModifier","httpStatus":null,"severity":"error","filePath":"phalcon/Time/Clock/FrozenClock.zep","lineNumber":71,"sourceCode":"    }\n\n    /**\n     * Mutates the clock to a new value. All consumers receive the same modification\n     *\n     * @throws InvalidModifier\n     */\n    public function adjust(string modifier) -> <static>\n    {\n        var ex, modified, priorWarning;\n        bool failed;\n\n        let failed = false;\n\n        if version_compare(phpversion(), \"8.3\", \">=\") {\n            try {\n                let modified = this->now->modify(modifier);\n            } catch Throwable, ex {\n                throw new InvalidModifier(modifier, ex);\n            }\n        } else {\n            /**\n             * Pre-8.3 fallback: DateTimeImmutable::modify() emits a warning\n             * instead of throwing on an invalid modifier, so the warning is\n             * captured through a temporary error handler. Remove this branch\n             * once the minimum supported PHP version reaches 8.3.\n             */\n            let priorWarning = globals_get(\"warning.enable\");\n\n            globals_set(\"warning.enable\", false);\n            set_error_handler(\n                function (number, message, file, line) {\n                    globals_set(\"warning.enable\", true);\n                },\n                E_WARNING\n            );\n","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Time/Clock/FrozenClock.zep#L53-L89","documentation":"Phalcon\\Time\\Clock\\FrozenClock is a frozen clock used in tests; adjust() shifts the stored DateTimeImmutable by a PHP date modifier string. On PHP >= 8.3, DateTimeImmutable::modify() throws on an unparseable modifier, and FrozenClock wraps that Throwable into Phalcon\\Time\\Clock\\Exceptions\\InvalidModifier ('Invalid modifier: \"...\"') with the original as $previous (phalcon/Time/Clock/FrozenClock.zep:71).","triggerScenarios":"$clock->adjust('in 2 hours'), $clock->adjust('whenever'), $clock->adjust('+1 dy') — any string DateTimeImmutable::modify() cannot parse. Works: '+2 hours', '-1 day', 'next Monday', 'first day of next month', 'midnight'.","commonSituations":"Test fixtures parameterized with human phrases ('in two days'); passing user/config input straight into adjust(); typos in relative formats; code that assumed strtotime() semantics (e.g. 'in 2 days' is valid for strtotime but not for DateTime::modify).","solutions":["Use a DateTime-relative format accepted by modify(): '+2 hours', '-1 day', 'next Monday', 'last day of next month'.","For computed targets, construct a new FrozenClock with the absolute time instead of adjusting by a string.","Catch Phalcon\\Time\\Clock\\Exceptions\\InvalidModifier when the modifier comes from external input, and fall back to a known-good modifier."],"exampleFix":"// before\n$clock->adjust('in 2 hours'); // 'in ...' is not a DateTime modifier\n\n// after\n$clock->adjust('+2 hours');","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"use Phalcon\\Time\\Clock\\Exceptions\\InvalidModifier;\n\ntry {\n    $clock->adjust($modifier);\n} catch (InvalidModifier $e) {\n    // $modifier came from data; keep the clock and report\n    $this->fail('Cannot adjust frozen clock: ' . $e->getMessage());\n}","preventionTips":["Restrict adjust() calls to literals in test code ('+2 hours', 'next Monday') so IDE/search can verify them.","Remember DateTime::modify() does not accept strtotime()-only formats like 'in 2 days'.","For absolute targets construct a new FrozenClock(new DateTimeImmutable($when)) instead of adjusting."],"tags":["phalcon","time","clock","datetime","modifier","testing"],"backgroundTag":"invalid-date-modifier","analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}