PdoFetchColumnFalsyValueLoss
warning native on by defaultGroup: Probable bugs
Detect fetchColumn result used as a truthiness condition that skips successful zero or empty-string results.
Example
<?php
function bad(PDOStatement $s) { if ($value = $s->fetchColumn()) { echo $value; } }Reported:
- line 2: Compare fetch failure strictly with false.
Detection
- Report fetchColumn result used as a truthiness condition that skips successful zero or empty-string results.
- Resolve builtin calls and named arguments before checking the contract. Project-local callees are considered only when their bodies or immutable summaries establish the required facts. The default is enabled, with positive proof required.
- For flow-dependent conditions, require a reachable source-to-use path with no intervening invalidation. Unknown calls, ambiguous aliases, recursion or analysis-budget exhaustion cannot establish definite facts.
Exceptions (no report)
- Strict false checks, explicit nonzero/nonempty filtering, boolean-column contracts and unknown PDO receivers are excluded.
- Unresolved targets, incomplete required facts, suppressed findings and PHP versions lacking the referenced API or language feature produce no report. User declarations shadowing builtin names are not builtin contracts.
Fix
Rewrite a sole assignment condition to strict false comparison while evaluating once, only when the column cannot legitimately contain boolean false.
A fix is offered only when the concrete prerequisites above are proven. Edits use exact source byte ranges, preserve comments and argument evaluation order, and introduce syntax supported by the configured PHP version. Never invent error-handling policy.
PHP versions
Apply only on PHP versions supporting the referenced APIs and syntax (within PHP 5.3–8.5). Builtin behavior and argument contracts follow the configured PHP version. Extension-specific calls require resolved extension API symbols; do not treat same-named application functions as extension calls.
Options
None. Enable or disable this rule through normal rule configuration.
Configure
In custos.json:
{
"rules": {
"PdoFetchColumnFalsyValueLoss": {
"enabled": false
}
}
}Suppress
Before the statement or declaration (or the first statement of the file):
// @custos-ignore PdoFetchColumnFalsyValueLoss