IntlCalendarSecondsPassedAsMilliseconds
warning native on by default quick-fix PHP ≥ 5.5Group: Probable bugs
Convert seconds to calendar milliseconds.
Example
<?php
$c = IntlCalendar::createInstance(); $c->setTime(time());Reported:
- line 2: Convert seconds to calendar milliseconds.
Detection
- Report resolved IntlCalendar::setTime with direct time(), or an unchanged local assigned time(), as its timestamp. Exclude arbitrary numbers and arithmetic/computed timestamps. Offer a fix only for the direct call argument.
- Resolve builtin functions, extension classes, method receivers, constants and named arguments. Follow unchanged locals and aliases only within the same bounded lexical scope. Require a reachable path; merge branch facts only when all incoming paths establish them.
- Emit one finding at the violating operation, not one per evidence statement. Rebinding, writes, by-reference escape, unresolved calls that can mutate relevant state, and exhausted analysis budgets remove proof.
- A local is not unchanged when it, or a variable whose value was copied into it, is captured by reference in a closure
useof the same scope or bound by acatchclause of that scope. A file-level variable is also a global: aglobaldeclaration naming it, or any$GLOBALSaccess anywhere in the file, removes proof as well. A by-value capture does not.
Exceptions (no report)
- Exclude shadowed builtins, unresolved receivers, incomplete syntax and unknown prerequisite facts. An extension function name alone does not prove an application function is that builtin.
- A dominating valid guard or repair described in Detection prevents the finding. Both legacy noinspection and custos-ignore forms suppress this ID.
- No report for
$t = time(); $f = function () use (&$t) { $t *= 1000; }; $f(); $c->setTime($t);: the closure may already have converted the value.
Fix
For direct resolved time() argument only, replace the exact source of the call with (original * 1000). When the argument is already parenthesized, keep those parentheses and everything between them and the call, and only append the multiplication to the call: (/* note */ time()) becomes (/* note */ time() * 1000). Evaluate once; the edit never covers a comment outside the call.
All edits use exact byte ranges and preserve comments and evaluation order. Offer no fix when its stated prerequisites cannot be proven or the replacement is unsupported by the configured PHP version.
PHP versions
Requires PHP 5.5 or later and the referenced extension API. Respect method-specific introduction versions within PHP 5.3–8.5; unsupported optional APIs cannot establish facts. Named arguments require PHP 8.0 or later.
Configure
In custos.json:
{
"rules": {
"IntlCalendarSecondsPassedAsMilliseconds": {
"enabled": false
}
}
}Suppress
Before the statement or declaration (or the first statement of the file):
// @custos-ignore IntlCalendarSecondsPassedAsMilliseconds