When Modernization Breaks Working Code: A Single-File Study of LLMs on Legacy PHP
Afridi Mahmud, Abid Hasan Khondaker, Sadif Ahmed, Md Nafiu Rahman, Rifat Shahriyar
cs.SE
2026-10-29
Five LLMs modernizing 100 legacy PHP files each broke 32–51 working files; the best left 59 compatible vs 83 untouched, while rule-based Rector kept 82.
Pasting a legacy file into a chat window and asking for a PHP 8.3 upgrade is something developers do every week. This paper measures a question nobody had quantified: is the result actually better than leaving the file alone?
Existing migration benchmarks (MigrationBench, VersiCode, JMigBench) score repository-level or function-level migration, usually with build or test feedback, and never compare against doing nothing. This study covers the middle setting: one complete file, no project context, no execution feedback, first answer only. That is exactly how chat assistants get used.
One principle organizes the design: every output is judged against the unchanged original.
The no-change baseline is the design decision that carries the paper. The original is runnable code; without comparing against it, any "resolved 53% of findings" score looks like progress.
| Approach | Compatible files | Broken / fixed | Preservation | Regressions |
| Unchanged | 83 | 0 / 0 | 100% | 0 |
| Rector | 82 | 7 / 6 | 97.7% | 12 |
| Claude Sonnet 4 | 59 | 32 / 8 | 76.3% | 126 |
| GPT-5 Codex | 58 | 33 / 8 | 77.0% | 122 |
| Gemini 2.5 Pro | 55 | 38 / 10 | 72.3% | 147 |
| Gemini 2.5 Flash | 50 | 40 / 7 | 62.7% | 198 |
| Llama 3.3 70B | 33 | 51 / 1 | 59.5% | 215 |
Every LLM lands significantly below the untouched originals (adjusted p ≤ 0.0021); Rector lands significantly above every LLM (p ≤ 0.0016) and is statistically indistinguishable from doing nothing. Rector repairs 62 originally failing checks, on par with four of the LLMs (58–68), while adding 12 regressions against their 122–215.
Split findings by necessity and the picture gets worse. Only 37 of 511 findings (7%) are required under PHP 8.3. Among the 73 compatible files needing no required change, LLMs break 36–60%; Rector breaks 8%. Gemini 2.5 Pro posts the highest modernization score (72.8% resolved) yet ranks third in compatible files, and 82–87% of what each model resolves is optional. On the 26 files that do contain required findings, LLMs fix 6–9 (Llama: 1) and break 5–7, roughly break-even; Rector fixes 6 and breaks 1.
Cause analysis: 66–81% of each LLM's regressed checks sit in files that fail to load at all. Typical errors include a non-void return type on the magic method set() and a ?callable property type that PHP forbids (Claude and Codex each make the set() mistake in three files). Catching these needs PHP's own rules, not the withheld project context.
Three conclusions transfer directly. A modern-looking diff from an LLM cannot be adopted as-is; in this setting all five models are net negative. Cheap guardrails help but do not close the gap: falling back to the original when php -l fails recovers 8–15 files per model, yet the best still reaches 69 against 83, so lint must be followed by load and behavior checks. And migration benchmarks should report a no-change baseline and separate modernization from preservation, because a 53.2% resolution rate looks like progress while losing 24 files net.
Rector's position is now pinned down: behavior preservation close to doing nothing, while still repairing required changes. An LLM workflow that beats it needs execution feedback and iteration; the single-shot answers tested here do not.
The authors' own list: checks cover selected paths, not complete behavior; the necessity classification involves judgment; the prompt's "PHP 8.3 standards" phrasing invites optional edits even though preservation was explicitly required; Rector both selected the sample and detects findings, which biases the sample toward patterns it recognizes (though this cannot explain LLM regressions in files needing no change); one repository, purposive sampling, one generation per file, with prompt sensitivity and repeated generation untested.
Two caveats the paper does not dwell on. Counting deprecations as failures lowers the baseline as well, which if anything favors modernization, so 83 is the conservative reading. All five models are 2025-era versions; whether newer ones still make set()-style mistakes is untested, though the evaluation design transfers unchanged.