← CodeClarityLab Home
Browse by Category
+ added · updated 7d
← Back to glossary

Late Static Binding — PHP 5.3 Feature

php PHP 5.3+ Intermediate
debt(d5/e1/b3/t7)
d5 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'specialist tool catches it' (d5). The detection_hints list phpstan and rector as the tools, both specialist static analysis tools. The code_pattern `new self()` is detectable by these tools but not by a default linter or compiler — it's syntactically valid and only wrong in certain inheritance contexts.

e1 Effort Remediation debt — work required to fix once spotted

Closest to 'one-line patch or single-call swap' (e1). The quick_fix is explicit: replace `new self()` with `new static()` (or `self::$property` with `static::$property`). This is a direct single-call textual substitution, often automatable via rector.

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

Closest to 'localised tax' (b3). The misuse is confined to static factory methods or inheritable static properties in a class hierarchy. It doesn't bleed across the entire codebase — only the affected class and its subclasses pay the cost. Other components are unaffected.

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

Closest to 'serious trap' (t7). The misconception field states explicitly that developers believe `self::` and `static::` are interchangeable — but self:: always resolves to the defining class at compile time while static:: resolves at runtime to the called class. This contradicts how most developers reason about inheritance (expecting runtime polymorphism), and the 'obvious' usage of self:: in a base factory method silently produces the wrong type without any error.

About DEBT scoring →

TL;DR

static:: (Late Static Binding, PHP 5.3) refers to the called class at runtime — unlike self:: which always refers to the class where the method is defined.

Explanation

PHP 5.3 introduced static:: for Late Static Binding. self:: always resolves to the class where the method was written. static:: resolves to the class that was called at runtime. Classic use case: static factory methods in inheritance. class Base { static function create() { return new static(); } } — new self() always creates Base; new static() creates the called subclass. LSB is also used for static properties in hierarchies: static::$table in an ORM base class. get_class($this) is the instance equivalent for dynamic resolution.

Common Misconception

self:: and static:: are interchangeable in static methods — self:: always refers to the defining class; static:: refers to the called class (runtime resolution).

Why It Matters

Without LSB, static factory methods in base classes always create base class instances — breaking the inheritance chain for fluent patterns.

Common Mistakes

  • Using self:: in static factory methods — breaks when called on subclasses.
  • Using static:: when self:: is intentionally needed (singleton base class).
  • Confusing static:: with $this (instance context).

Code Examples

✗ Vulnerable
class Base {
    public static function create(): static {
        return new self(); // Always Base — broken in subclasses
    }
}

class Child extends Base {}
Child::create(); // Returns Base, not Child!
✓ Fixed
class Base {
    public static function create(): static {
        return new static(); // Returns calling class
    }
}

class Child extends Base {}
Child::create(); // Returns Child instance

Added 23 Mar 2026
Views 22
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 1 ping F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 1 ping T 2 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 2 pings S 0 pings S 1 ping M 0 pings T 0 pings W 0 pings T 0 pings F
No pings yet today
No pings yesterday
Amazonbot 9 Unknown AI 4 Perplexity 2 Google 2 ChatGPT 1 Ahrefs 1
crawler 17 pre-tracking 2
DEV INTEL Tools & Severity
🟡 Medium ⚙ Fix effort: Low
⚡ Quick Fix
Replace new self() with new static() in factory methods meant to be inherited. Replace self::$property with static::$property for inheritable static properties.
📦 Applies To
PHP 5.3+ web cli queue-worker
🔗 Prerequisites
🔍 Detection Hints
new self\(\)
Auto-detectable: ✓ Yes phpstan rector
🤖 AI Agent
Confidence: High False Positives: Medium ✓ Auto-fixable Fix: Low Context: Class Tests: Update

✓ schema.org compliant