Skip to content

TraitInstantiation ​

error native on by default PHP ≥ 5.4

Group: Probable bugs

Instantiate a class using the trait.

Example ​

Finding:

php
<?php
trait Track {} new Track();

Reported:

  • line 2: Instantiate a class using the trait.

Detection ​

  • Report new applied to a resolved trait declaration, including imported aliases.
  • 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) ​

  • Do not confuse trait use clauses or same-spelled names in other namespaces with instantiation.
  • 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.4.

Configure ​

In custos.json:

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

Suppress ​

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

php
// @custos-ignore TraitInstantiation

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