Skip to content

AbstractClassInstantiation ​

error native on by default

Group: Probable bugs

Instantiate a concrete class.

Example ​

Finding:

php
<?php
abstract class Work {} new Work();

Reported:

  • line 2: Instantiate a concrete class.

Detection ​

  • Report a new expression whose resolved class declaration is abstract, including a literal class-string traced to that declaration.
  • new self counts as resolved when it is evaluated by the body of a method declared in a named abstract class: the instantiated class is then that enclosing class.
  • Emit one finding per violating operation. Flow facts require a reachable path with no intervening mutation, escaped alias or unknown call involving the tracked value. When the proof is inconclusive, nothing is reported.

Exceptions (no report) ​

  • Dynamic class names, unresolved ancestors and factory calls are excluded.
  • new static and new parent are never resolved. new self stays unresolved inside a closure or arrow function (its class scope can be rebound at run time), inside a trait (it names the using class), inside an anonymous class, in a parameter default or attribute argument, and outside a class method.
  • 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.

PHP versions ​

Available throughout PHP 5.3–8.5.

Configure ​

In custos.json:

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

Suppress ​

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

php
// @custos-ignore AbstractClassInstantiation

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