← Home ← Codex ← DEBT ← Engine
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 114
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
1 ping T 1 ping F 0 pings S 0 pings S 1 ping M 1 ping T 0 pings W 0 pings T 0 pings F 0 pings S 0 pings S 0 pings M 1 ping 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 0 pings T 2 pings F 1 ping S 0 pings S 0 pings M 0 pings T 1 ping W 0 pings T 0 pings F
No pings yet today
No pings yesterday
Scrapy 19 Amazonbot 9 Perplexity 8 ChatGPT 6 Google 6 SEMrush 6 Ahrefs 5 Bing 4 PetalBot 4 Meta AI 3 Unknown AI 3 Claude 3 Brave Search 3 Majestic 2 Twitter/X 2 Applebot 2
crawler 78 crawler_json 5 pre-tracking 2
🧱 FUNDAMENTALS — new to this? Start with the ground floor.
Object general A bundle of data (properties) and the behaviour that works on it (methods), created from a class blueprint — accessed as $user->name and $user->save().

Objects are the dominant way code is organised — frameworks, libraries, and your own domain models are all classes and objects. Reference semantics specifically explains a whole family of 'my data changed by itself' bugs.

💡 When handing an object to code you do not control, decide explicitly: share it, or clone it. Never accidentally share.

Ask Codex about Object →
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
🔵 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
🤖 AI Agent
Confidence: Low False Positives: High ✗ Manual fix Fix: High Context: File


✓ schema.org compliant