PdoFetchIntoRetainsSharedRows
warning native off by defaultGroup: Probable bugs
Identify array append of an unchanged fetch return in a loop when statement FETCH_INTO mode targets same known object on every fetch. Cloned snapshots and immediate single-row consumption exclude.
Detection
- Report array append of an unchanged fetch return in a loop when statement FETCH_INTO mode targets same known object on every fetch. Cloned snapshots and immediate single-row consumption exclude.
- Resolve builtin functions, classes, constants and methods, including imports and supported named arguments. Follow only bounded local facts within one lexical scope. Receiver and argument provenance must establish the specific API contract; variable names and comments never prove intent.
- The statement is a
PDOStatementby its resolved type, or a local variable whose latest write is an unconditional plain assignment of a builtinPDO::query()result. The second form keeps the rule working on targets below PHP 8.0, wherePDO::query()carries no native return type. - The governing
setFetchMode()call is the last one on the statement that runs unconditionally before the loop (or whose success guards the loop). It must selectPDO::FETCH_INTOwith an object target. - Report one finding per violating operation. A reachable path, unchanged value identity and applicable API behavior are required. Intervening mutation, unknown calls involving tracked values, escaped aliases or exhausted analysis budgets invalidate proof.
Exceptions (no report)
- Exclude unresolved required symbols, user-defined lookalikes, incomplete syntax, unknown required values and unsupported versions.
- No report when another
setFetchMode()call on the same statement follows the governing call and either sits on a conditional path before the loop or runs inside the fetch loop or a loop enclosing it: the mode or its target may differ between fetches. Calls after the outermost loop are irrelevant. - No report when the append is followed, in its own statement list or an enclosing one inside the fetch loop, by an unconditional
return,throw,exitor abreakthat leaves the fetch loop: at most one row is retained, so nothing is shared. Abreakthat only leaves an inner loop or aswitchdoes not count, and neither does a conditional exit. - Both
@custos-ignore PdoFetchIntoRetainsSharedRowsand@noinspection PdoFetchIntoRetainsSharedRowssuppress this native rule.
Fix
None. A repair requires a semantic decision or application error-handling policy.
PHP versions
Available in PHP 5.3–8.5 where the referenced API exists. Do not apply extension contracts when the resolved API is unavailable. Gate syntax and version-specific behavior to the configured target.
Configure
In custos.json:
json
{
"rules": {
"PdoFetchIntoRetainsSharedRows": {
"enabled": true
}
}
}Suppress
Before the statement or declaration (or the first statement of the file):
php
// @custos-ignore PdoFetchIntoRetainsSharedRows