← Home ← Codex ← DEBT ← Engine
Browse by Category
+ added · updated 7d
← Back to glossary

abstract (Classes & Methods)

PHP PHP 5.0+ Beginner
debt(d1/e2/b2/t4)
d1 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'caught instantly' (d1). PHP itself throws a fatal error if you try to instantiate an abstract class or fail to implement abstract methods. Additionally, phpstan, psalm, and phpcs all catch misuse patterns like abstract classes without abstract methods. Most errors are compile/parse-time fatal errors, making detection essentially instant.

e2 Effort Remediation debt — work required to fix once spotted

Closest to 'one-line patch or single-call swap' (e1), +1 because some fixes involve adding/removing the abstract keyword or converting to an interface, which may touch a small handful of files (the class and its subclasses). The quick_fix is straightforward: switch between abstract and interface or add missing implementations. Typically a simple parameterized fix but slightly more than a single line.

b2 Burden Structural debt — long-term weight of choosing wrong

Closest to 'minimal commitment' (b1), +1. Abstract classes are a localized design choice that affects only the class hierarchy in question. They apply across all PHP contexts (web, cli, queue-worker) but the structural weight is low — it's a single inheritance point, not a system-defining architecture decision. There's a small ongoing tax in that subclasses must conform, but it's well-contained.

t4 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'notable trap' (t5), -1. The misconception states developers think abstract classes are 'just documentation hints' when PHP enforces them strictly with fatal errors. This is a real but moderate trap. Common mistakes include assuming abstract methods can have a body, using abstract when interface is more appropriate, and declaring abstract classes without abstract methods. A competent developer from other OOP languages would mostly get it right, but the specific PHP behaviors (e.g., no body on abstract methods, class must be declared abstract if it has abstract methods) can trip people up.

About DEBT scoring →

Also Known As

abstract PHP abstract keyword

TL;DR

PHP keyword that prevents instantiation and enforces method implementation in subclasses.

Explanation

The abstract keyword in PHP is used to declare classes and methods that define incomplete behaviour. An abstract class cannot be instantiated and may contain both concrete methods and abstract method declarations. Any class containing at least one abstract method must itself be declared abstract. Abstract methods define a required signature without implementation, forcing subclasses to provide concrete logic. Unlike interfaces, abstract classes can include state and shared behaviour but are limited by single inheritance. PHP 8.0+ also allows abstract methods inside traits, enabling partial contracts in reusable components.

Common Misconception

Abstract classes are just documentation hints. In reality, PHP enforces them strictly — instantiation and missing implementations result in fatal errors.

Why It Matters

The abstract keyword enforces incomplete designs at the language level — preventing invalid instantiation and ensuring required methods are implemented before use.

Common Mistakes

  • Declaring abstract classes without abstract methods — unnecessary restriction.
  • Forgetting that a class with abstract methods must itself be abstract.
  • Using abstract instead of interface when no shared implementation exists.
  • Assuming abstract methods can have a body — they cannot.

Avoid When

  • All methods are abstract — use an interface instead.
  • You only want to prevent instantiation without defining a contract.
  • No shared behaviour or structure exists.

When To Use

  • Defining required methods without implementation.
  • Providing partial implementation with enforced extension points.
  • Building template workflows with override steps.

Code Examples

💡 Note
Abstract methods define required steps, while concrete methods define shared workflow (Template Method pattern).
✗ Vulnerable
// ❌ Invalid design — abstract used instead of interface
abstract class Logger {
    abstract public function log(string $message): void;
}
✓ Fixed
abstract class Report {
    abstract protected function header(): string;
    abstract protected function body(): string;

    public function generate(): string {
        return $this->header() . $this->body();
    }
}

final class HtmlReport extends Report {
    protected function header(): string {
        return '<h1>Report</h1>';
    }

    protected function body(): string {
        return '<p>Content</p>';
    }
}

Added 15 Mar 2026
Edited 27 Mar 2026
Views 138
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings W 0 pings T 0 pings F 0 pings S 1 ping S 1 ping M 1 ping T 0 pings W 0 pings T 1 ping F 1 ping S 1 ping S 1 ping M 1 ping T 0 pings W 0 pings T 1 ping F 0 pings S 1 ping S 0 pings M 1 ping T 0 pings W 0 pings T 1 ping F 0 pings S 1 ping S 0 pings M 0 pings T 0 pings W 0 pings T
No pings yet today
No pings yesterday
PetalBot 13 Amazonbot 11 Perplexity 8 Ahrefs 8 Scrapy 8 ChatGPT 7 SEMrush 6 Unknown AI 5 Google 5 Brave Search 2 Applebot 2 Bing 2 Majestic 1 Meta AI 1 Sogou 1 Twitter/X 1
crawler 76 crawler_json 4 your_contextpost 1
🧱 FUNDAMENTALS — new to this? Start with the ground floor.
PHP php A server-side scripting language that generates web pages and APIs — the code runs on the server, and only its output (usually HTML or JSON) reaches the browser.

PHP is often the first server-side language people meet, and understanding its execution model — script starts fresh on every request, no memory between requests — explains most of how the web backend works: sessions, databases, and caching all exist to bridge that per-request amnesia.

💡 Start with PHP 8.x, declare(strict_types=1), and PDO — skip any tutorial that mentions mysql_query().

Ask Codex about PHP →
DEV INTEL Tools & Severity
🟢 Low ⚙ Fix effort: Low
⚡ Quick Fix
Use abstract when a class has incomplete methods that subclasses must implement; if all methods are abstract, use an interface.
📦 Applies To
PHP 5.0+ web cli queue-worker
🔍 Detection Hints
abstract class with no abstract methods OR class contains abstract method but is not declared abstract
Auto-detectable: ✓ Yes phpstan psalm phpcs
⚠ Related Problems
🤖 AI Agent
Confidence: Medium False Positives: Medium ✗ Manual fix Fix: Low Context: Class


✓ schema.org compliant