Skip to content

PdoReferenceBindingVariableReuse ​

warning native on by default

Group: Probable bugs

Detect two distinct PDO markers bound through bindParam to the same scalar local identity, with its value changed between bindings and before execute.

Example ​

php
<?php
function bad(PDO $pdo) { $s = $pdo->prepare('SELECT :a, :b'); $v = 0; $s->bindParam(':a', $v); $v = 1; $s->bindParam(':b', $v); $v = 2; $s->execute(); }

Reported:

  • line 2: Bind distinct parameters to distinct scalar identities.

Detection ​

  • Report two distinct PDO markers bound through bindParam to the same scalar local identity, with its value changed between bindings and before execute.
  • 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) ​

  • Separate variables, bindValue, deliberate identical bindings without intervening change, unknown aliases and references escaping invalidate proof.
  • 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 ​

No automatic fix: copying values at binding time may not preserve the intended first binding.

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:

json
{
  "rules": {
    "PdoReferenceBindingVariableReuse": {
      "enabled": false
    }
  }
}

Suppress ​

Before the statement or declaration (or the first statement of the file):

php
// @custos-ignore PdoReferenceBindingVariableReuse

Released under the MIT License. Native rules and rules modeled on Php Inspections (EA Extended); independent clean-room implementation.