ereg() / eregi() — POSIX Regex Removed in PHP 7
debt(d5/e3/b3/t5)
Closest to 'specialist tool catches it' (d5). Detection_hints lists rector and phpcs as the tools — both are specialist/opt-in static analysis tools, not default linters or compiler errors. The code_pattern is well-defined, so automated detection is reliable once the tool is configured, but it requires deliberate tooling setup.
Closest to 'simple parameterised fix' (e3). The quick_fix states Rector can auto-convert ereg/eregi to preg_match, making this largely mechanical. However, the common_mistakes note that direct translation requires adding delimiters and /i flags, meaning a small but consistent pattern of adjustment is needed beyond a pure one-line swap. It stays within e3 rather than e1 because of these systematic but non-trivial conversion details.
Closest to 'localised tax' (b3). These functions apply to PHP 3.0–5.6 codebases in web and CLI contexts, but once migrated, the burden is gone entirely. The burden is contained to legacy code that hasn't been upgraded; it doesn't impose ongoing weight on the rest of the codebase architecture. It's a one-time migration cost rather than a persistent structural drag.
Closest to 'notable trap' (t5). The misconception field explicitly states that developers assume ereg() is just an older alias for preg_match(), when in fact they use different regex flavours (POSIX vs PCRE) with different syntax and capabilities. The common_mistakes confirm that direct translation without delimiters or without the /i flag is a documented and frequent gotcha. This is a well-known but easily-missed distinction that catches many developers during migration.
TL;DR
Explanation
ereg() and eregi() (case-insensitive) used POSIX Extended Regular Expressions. Deprecated in PHP 5.3, removed in PHP 7.0. PCRE (Perl-Compatible Regular Expressions) via preg_match() is faster and far more capable. Migration: ereg('pattern', $string, $matches) → preg_match('/pattern/', $string, $matches). Delimiters required in preg_match. eregi → preg_match with /i flag. ereg_replace → preg_replace. split → preg_split. Rector handles this migration automatically.
Common Misconception
Why It Matters
Common Mistakes
- Not running Rector to auto-migrate ereg to preg_match.
- Direct translation missing delimiters: ereg('foo') → preg_match('foo') — wrong, needs /foo/.
- Forgetting eregi → preg_match with /i flag.
Code Examples
if (ereg('^[a-z]+$', $input)) { } // Fatal in PHP 7+
eregi('[0-9]', $string); // Case-insensitive digit check
if (preg_match('/^[a-z]+$/i', $input)) { } // PCRE
if (preg_match('/[0-9]/', $string)) { } // Digits