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

Migrating from PHP 4 to PHP 5

PHP PHP 4.0+ Intermediate
debt(d5/e5/b5/t7)
d5 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'specialist tool catches' (d5). Tools like Rector and phpcs (cited in detection_hints) can detect PHP 4 patterns like 'var $' declarations and old-style constructors, but the semantic changes in object behavior (pass-by-reference vs pass-by-value) require more careful analysis beyond simple pattern matching.

e5 Effort Remediation debt — work required to fix once spotted

Closest to 'touches multiple files / significant refactor' (e5). The quick_fix describes replacing var keywords, adding constructors/type hints, wrapping errors in try/catch, and testing object assignment code — this is a systematic refactor touching many files across a codebase, but not a full architectural rewrite.

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

Closest to 'persistent productivity tax' (b5). Legacy PHP 4 code that hasn't been migrated imposes ongoing maintenance costs. The applies_to scope covers web and cli contexts broadly, and unmigrated code creates friction for developers unfamiliar with PHP 4 patterns, but it doesn't define system architecture.

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

Closest to 'serious trap' (t7). The misconception explicitly states 'PHP 4 code mostly works in PHP 5 — most code does run but object semantics changed, which can cause subtle bugs where shared objects were relied upon.' This contradicts how developers familiar with PHP 5+ expect objects to behave, creating silent semantic bugs rather than crashes.

About DEBT scoring →

TL;DR

PHP 4→5 migration: objects now pass by reference, add visibility (public/protected/private), replace var with typed properties, fix object assignment semantics, and adopt try/catch.

Explanation

Key PHP 4→5 breaking changes: (1) Object semantics: assignments now copy the handle (reference semantics) — $b = $a no longer clones. Existing =& $obj patterns still work but are now redundant. (2) var → public/protected/private. (3) try/catch available — replace die() and trigger_error(). (4) SPL data structures available. (5) SimpleXML, SOAP, DOM extensions redesigned. (6) mysql_ still works but deprecated (removed PHP 7). Migration tools: PHP_CompatInfo, PHPCS with compatibility sniffs. Test with E_ALL | E_STRICT error reporting to find issues.

Common Misconception

PHP 4 code mostly works in PHP 5 — most code does run but object semantics changed, which can cause subtle bugs where shared objects were relied upon.

Why It Matters

Historical knowledge — millions of lines of PHP 4 code still exist in legacy systems and require careful migration to avoid introducing subtle bugs.

Common Mistakes

  • Not testing object mutation after migration — shared object behaviour changed.
  • Keeping var keyword — works but signals unmodernised code.
  • Not converting to try/catch — missed opportunity for better error handling.

Code Examples

✗ Vulnerable
// PHP 4 class:
class User {
    var $name;
    var $email;
    function getName() { return $this->name; }
}
✓ Fixed
// PHP 5 style:
class User {
    private string $name;
    private string $email;

    public function __construct(string $name, string $email) {
        $this->name  = $name;
        $this->email = $email;
    }

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

Added 23 Mar 2026
Edited 13 Jun 2026
Views 106
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
1 ping W 0 pings T 1 ping F 0 pings S 0 pings S 0 pings M 1 ping T 0 pings W 1 ping T 1 ping 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 1 ping S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T
No pings yet today
No pings yesterday
Amazonbot 11 Google 10 PetalBot 10 ChatGPT 7 Ahrefs 7 SEMrush 5 Unknown AI 3 Perplexity 2 Scrapy 2 Brave Search 2 Applebot 2 Meta AI 1 Twitter/X 1 Bing 1 Sogou 1
crawler 60 crawler_json 4 pre-tracking 1
🧱 FUNDAMENTALS — new to this? Start with the ground floor.
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
🟡 Medium ⚙ Fix effort: High
⚡ Quick Fix
Replace var with public/private/protected. Add constructors and type hints. Wrap errors in try/catch. Test all object assignment code for changed semantics.
📦 Applies To
PHP 4.0+ web cli
🔗 Prerequisites
🔍 Detection Hints
\bvar \$
Auto-detectable: ✓ Yes rector phpcs
🤖 AI Agent
Confidence: High False Positives: Low ✓ Auto-fixable Fix: Medium Context: Class Tests: Update

✓ schema.org compliant