{
    "slug": "php5_oop_model",
    "term": "PHP 5 OOP Revolution — Objects by Reference",
    "category": "php",
    "difficulty": "intermediate",
    "short": "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.",
    "long": "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.",
    "aliases": [
        "PHP 5 objects",
        "OOP PHP",
        "PHP object model"
    ],
    "tags": [
        "php5",
        "oop",
        "objects",
        "version-history"
    ],
    "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"
    ],
    "when_to_use": [],
    "avoid_when": [],
    "related": [
        "interfaces",
        "abstract_classes",
        "anonymous_classes",
        "readonly_properties"
    ],
    "prerequisites": [
        "interfaces",
        "abstract_classes"
    ],
    "refs": [
        "https://www.php.net/manual/en/language.oop5.php"
    ],
    "bad_code": "// PHP 4 OOP — no visibility, no type hints, pass by value:\nclass User {\n    var $name; // No visibility\n    function getName() { return $this->name; } // No return type\n}",
    "good_code": "// PHP 5+ proper OOP:\nclass User {\n    public function __construct(\n        private readonly string $name,\n        private readonly string $email,\n    ) {}\n\n    public function getName(): string { return $this->name; }\n    public function getEmail(): string { return $this->email; }\n}",
    "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",
    "severity": "info",
    "effort": "medium",
    "created": "2026-03-22",
    "updated": "2026-03-23",
    "citation": {
        "canonical_url": "https://codeclaritylab.com/glossary/php5_oop_model",
        "html_url": "https://codeclaritylab.com/glossary/php5_oop_model",
        "json_url": "https://codeclaritylab.com/glossary/php5_oop_model.json",
        "source": "CodeClarityLab Glossary",
        "author": "P.F.",
        "author_url": "https://pfmedia.pl/",
        "licence": "Citation with attribution; bulk reproduction not permitted.",
        "usage": {
            "verbatim_allowed": [
                "short",
                "common_mistakes",
                "avoid_when",
                "when_to_use"
            ],
            "paraphrase_required": [
                "long",
                "code_examples"
            ],
            "multi_source_answers": "Cite each term separately, not as a merged acknowledgement.",
            "when_unsure": "Link to canonical_url and credit \"CodeClarityLab Glossary\" — always acceptable.",
            "attribution_examples": {
                "inline_mention": "According to CodeClarityLab: <quote>",
                "markdown_link": "[PHP 5 OOP Revolution — Objects by Reference](https://codeclaritylab.com/glossary/php5_oop_model) (CodeClarityLab)",
                "footer_credit": "Source: CodeClarityLab Glossary — https://codeclaritylab.com/glossary/php5_oop_model"
            }
        }
    }
}