PHP 5 OOP Revolution — Objects by Reference
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; }
}
Tags
🤝 Adopt this term
£79/year · your link shown here
Added
22 Mar 2026
Edited
23 Mar 2026
Views
33
🤖 AI Guestbook educational data only
|
|
Last 30 days
Agents 1
No pings yesterday
Perplexity 8
Amazonbot 7
ChatGPT 3
Unknown AI 3
Google 3
SEMrush 3
Meta AI 2
Majestic 1
Ahrefs 1
Also referenced
How they use it
crawler 27
crawler_json 2
pre-tracking 2
Related categories
⚡
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