Global Function Style vs OOP Evolution
debt(d5/e5/b5/t3)
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).
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.
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.
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.
TL;DR
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
Why It Matters
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
// 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'];
}
// Modern — OOP with PDO:
class UserRepository {
public function __construct(private PDO $pdo) {}
public function findAll(): array {
return $this->pdo->query('SELECT * FROM users')->fetchAll();
}
}