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

PHP 5 OOP Revolution — Objects by Reference

PHP PHP 5.0+ Intermediate
debt(d5/e3/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 Rector and PHPCS as tools. The specific code pattern — the `$obj = &new ClassName()` reference-new idiom from PHP 4, absence of visibility keywords, no interfaces — is not caught by a default linter but Rector (a specialist refactoring/upgrade tool) and PHPCS with appropriate rulesets can flag these patterns. Not instantly caught by the compiler and not silently failing in production either.

e3 Effort Remediation debt — work required to fix once spotted

Closest to 'simple parameterised fix' (e3). The quick_fix notes that legacy PHP 4-era code should be reviewed and treated as potentially relying on copy behaviour. Fixing involves replacing the `&new` idiom and auditing object-passing assumptions — more than a single-line swap but generally contained within individual components or files rather than a codebase-wide architectural rework.

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

Closest to 'localised tax' (b3). The applies_to covers web, cli, and queue-worker contexts broadly, but this is fundamentally a version-history concept. Once a codebase is on PHP 5+, the burden is mostly a one-time audit of legacy code rather than a persistent ongoing tax on maintainers. The tag 'version-history' signals it's a historical inflection point, not an ongoing architectural choice.

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

Closest to 'serious trap' (t7). The misconception is explicit: developers assume PHP always passed objects by reference, when in fact PHP 4 copied objects on every assignment. The common_mistakes reinforce this — confusing 'passed by handle' with 'passed by reference' and not realising PHP 4 limitations explain procedural-heavy inherited codebases. This contradicts what developers expect from a language claiming OOP support, placing it solidly at t7.

About DEBT scoring →

Also Known As

PHP 5 objects OOP PHP PHP object model

TL;DR

PHP 5 completely replaced PHP 4's object model — objects became reference-counted handles rather than copies, enabling true OOP with interfaces, abstract classes, visibility, and exceptions.

Explanation

PHP 4 passed objects by value like any other variable, meaning every function call or assignment copied the entire object. PHP 5 (2004) introduced a handle-based object model: variables hold a reference to an object, not a copy. PHP 5 also added interfaces, abstract classes, public/protected/private visibility, static methods and properties, __autoload, exceptions, and type hints for objects and arrays. This was the release that made PHP viable for enterprise-scale applications and frameworks like Symfony and Zend Framework.

Common Misconception

PHP has always had proper OOP — PHP 4 had classes but objects were copied on every assignment, making complex OOP patterns inefficient or broken.

Why It Matters

Understanding the PHP 4 to 5 object model change explains why so much pre-2004 PHP code is procedural and why modern PHP frameworks require PHP 5+.

Common Mistakes

  • Assuming PHP always passed objects by reference
  • Confusing passed by handle with passed by reference — clone() still creates a copy
  • Not realising PHP 4 OOP limitations explain the procedural-heavy codebase you just inherited

Code Examples

✗ Vulnerable
// PHP 4 OOP — no visibility, no type hints, pass by value:
class User {
    var $name; // No visibility
    function getName() { return $this->name; } // No return type
}
✓ Fixed
// PHP 5+ proper OOP:
class User {
    public function __construct(
        private readonly string $name,
        private readonly string $email,
    ) {}

    public function getName(): string { return $this->name; }
    public function getEmail(): string { return $this->email; }
}

Added 22 Mar 2026
Edited 23 Mar 2026
Views 75
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings T 0 pings W 1 ping T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 1 ping W 2 pings T 3 pings F 2 pings S 7 pings S 4 pings M 1 ping T 0 pings W 2 pings T 1 ping F 0 pings S 0 pings S 0 pings M 0 pings T 1 ping W 0 pings T 0 pings F 0 pings S 1 ping S 1 ping M 1 ping T 0 pings W
No pings yet today
PetalBot 1
Scrapy 19 Amazonbot 9 Perplexity 8 ChatGPT 5 Google 5 SEMrush 5 Meta AI 3 Unknown AI 3 Ahrefs 3 Majestic 2 Claude 2 Bing 2 PetalBot 1
crawler 60 crawler_json 5 pre-tracking 2
DEV INTEL Tools & Severity
🔵 Info ⚙ Fix effort: Medium
⚡ Quick Fix
When reading legacy PHP 4-era code, treat all object usage as potentially broken — it was written without proper OOP semantics and may rely on copy behaviour
📦 Applies To
PHP 5.0+ web cli queue-worker
🔗 Prerequisites
🔍 Detection Hints
$obj = &new ClassName() reference-new idiom from PHP 4; no visibility keywords; no interfaces used
Auto-detectable: ✓ Yes rector phpcs
⚠ Related Problems
🤖 AI Agent
Confidence: Low False Positives: High ✗ Manual fix Fix: High Context: File


✓ schema.org compliant