Skip to content

PriorityQueueExtractionShapeMismatch ​

warning native on by default PHP ≥ 5.3

Group: Probable bugs

Match the priority queue extraction mode.

Example ​

Finding:

php
<?php
$q = new SplPriorityQueue(); $q->insert("task", 5); $q->extract()["priority"];

Reported:

  • line 2: Match the priority queue extraction mode.

Detection ​

  • Track builtin SplPriorityQueue mode (default EXTR_DATA) and literal inserted data. Report indexing extracted/current/top values by data or priority when the proven extraction mode does not produce that field and the inserted data type cannot provide it. EXTR_BOTH provides both fields; EXTR_PRIORITY provides only priority itself. Report the indexed expression.
  • The mode is proven only by setExtractFlags calls that always run before the extraction. A setExtractFlags call on the queue variable that merely may run first (inside a branch, a loop, a short-circuit or ternary operand, a nested closure or arrow function, or later in a loop that also contains the extraction) leaves the mode unknown. An insert call that merely may run first never proves the queue holds a value, but its data and priority still count as possible extracted shapes.
  • Emit one finding per violating operation. Flow facts require a reachable path with no intervening mutation, escaped alias, unknown call involving the tracked value or analysis-budget exhaustion. Uncertain facts cannot prove a violation.

Exceptions (no report) ​

  • Unknown inserted data (which may itself be an array), overridden extraction behavior or mode invalidated by unknown calls prevent a finding.
  • A conditional or deferred mode change before the extraction, or a conditional insertion of non-literal data, prevents a finding. Calls that can only run after the extraction do not.
  • Exclude shadowed builtin symbols, unresolved required types, incomplete syntax and unsupported PHP versions.

Fix ​

No automatic fix. Choosing a repair requires runtime information, error-handling policy or a semantic decision.

All edits use exact byte ranges, preserve comments and evaluation order, and require syntax supported by the target PHP version. A fix must never add an evaluation or silently change unrelated arguments.

PHP versions ​

Minimum PHP 5.3.

Configure ​

In custos.json:

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

Suppress ​

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

php
// @custos-ignore PriorityQueueExtractionShapeMismatch

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