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

Global Function Style vs OOP Evolution

PHP PHP 4.0+ Beginner
debt(d5/e5/b5/t3)
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 — both are specialist static analysis/linting tools that can flag mysql_ extension calls and unnamespaced global functions. This isn't caught by the compiler or a default linter in the typical IDE sense, but dedicated tools like Rector can automate detection of the specific patterns (mysql_query|mysql_fetch|mysql_connect).

e5 Effort Remediation debt — work required to fix once spotted

Closest to 'touches multiple files / significant refactor in one component' (e5). The quick_fix says: wrap procedural code in namespaced classes, replace mysql_ with PDO, use Composer autoloading, and add type hints progressively. This is clearly more than a one-line patch — it touches data access layers, function call sites across files, and potentially autoloading configuration — but it's not a full architectural rework either.

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

Closest to 'persistent productivity tax' (b5). The concept applies to web and cli contexts broadly. Legacy mysql_ calls and unnamespaced global functions impose a sustained maintenance cost: every developer working in a legacy codebase must understand the procedural patterns, avoid adding new mysql_ calls, and work around naming collision risks. It slows down multiple work streams (testing, refactoring, onboarding) but doesn't fully define the system's shape.

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

Closest to 'minor surprise (one edge case)' (t3). The misconception field is specific and bounded: developers may wrongly believe built-in global functions like array_map() are deprecated because of PHP's OOP evolution. This is a contained misunderstanding — once corrected, it's not a deeply contradictory behaviour. The common mistake of keeping mysql_ calls is a known, documented gotcha rather than a catastrophic or systemic trap.

About DEBT scoring →

TL;DR

PHP 4's procedural global-function style evolved into PHP 5 OOP — understanding the transition explains why modern PHP has both paradigms and how to migrate legacy procedural code.

Explanation

PHP 4 was primarily procedural: functions like mysql_query(), ereg(), split() in global scope, state managed through global variables, no namespaces, everything in include files. PHP 5 introduced proper OOP (classes with visibility, interfaces, abstract classes). PHP 7 added scalar types. Modern PHP is primarily OOP with namespaces and Composer, but the global function library remains (date(), array_map(), file_get_contents()). Legacy codebases often mix both — procedural logic with OOP classes. Migration path: wrap procedural code in classes, add namespaces, replace mysql_ with PDO, use Composer autoloading.

Common Misconception

PHP functions like array_map() are deprecated — built-in global functions are permanent. The OOP evolution affected application code structure, not the standard library.

Why It Matters

Understanding the procedural→OOP transition helps identify which patterns in legacy codebases need modernisation and which global functions are still appropriate to use.

Common Mistakes

  • Wrapping every function in a class unnecessarily — global functions are fine for pure utility.
  • Not namespacing custom global functions — use namespaces to avoid collisions.
  • Keeping mysql_ extension calls instead of migrating to PDO.

Code Examples

✗ Vulnerable
// PHP 4 style — global state, no OOP:
global $db;
$result = mysql_query('SELECT * FROM users', $db);
while ($row = mysql_fetch_array($result)) {
    echo $row['name'];
}
✓ Fixed
// Modern — OOP with PDO:
class UserRepository {
    public function __construct(private PDO $pdo) {}

    public function findAll(): array {
        return $this->pdo->query('SELECT * FROM users')->fetchAll();
    }
}

Added 23 Mar 2026
Views 38
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings T 1 ping W 1 ping T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 1 ping W 0 pings T 1 ping F 0 pings S 0 pings S 1 ping M 0 pings T 0 pings W 1 ping T 1 ping F 0 pings S 0 pings S 0 pings M 0 pings T 2 pings W 0 pings T 0 pings F 0 pings S 1 ping S 1 ping M 0 pings T 0 pings W
No pings yet today
No pings yesterday
Amazonbot 9 Google 6 Unknown AI 3 Ahrefs 3 Scrapy 3 Perplexity 2 Claude 2 SEMrush 2 ChatGPT 1 Meta AI 1 Majestic 1 PetalBot 1
crawler 28 crawler_json 4 pre-tracking 2
DEV INTEL Tools & Severity
🟡 Medium ⚙ Fix effort: High
⚡ Quick Fix
Wrap procedural code in namespaced classes. Replace mysql_ with PDO. Use Composer autoloading. Add type hints progressively.
📦 Applies To
PHP 4.0+ web cli
🔗 Prerequisites
🔍 Detection Hints
mysql_query|mysql_fetch|mysql_connect
Auto-detectable: ✓ Yes rector phpcs
🤖 AI Agent
Confidence: High False Positives: Low ✗ Manual fix Fix: High Context: File Tests: Update
CWE-89


✓ schema.org compliant