arXiv:2610.40269cs.SEOct 2026

Manuscript Offprint

arXiv:2610.40269

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

Afridi Mahmud

Bangladesh University of Engineering and Technology

Bangladesh

afridimahmud99@gmail.com

Abid Hasan Khondaker

Bangladesh University of Engineering and Technology

Bangladesh

abidhasan7116@gmail.com

Sadif Ahmed

BRAC University

Bangladesh

ahmedsadif67@gmail.com

Md Nafiu Rahman

BRAC University

Bangladesh

nafiu.rahman@gmail.com

Rifat Shahriyar

Bangladesh University of Engineering and Technology

Bangladesh

rifat@cse.buet.ac.bd

Abstract—Pasting a legacy file into an LLM and asking it to “modernize this” is an easy shortcut. But is the result better than leaving the code alone? In this paper, we study this single-file setting with five LLMs, each asked to modernize 100 WordPress 4.0 PHP files to PHP 8.3 while preserving behavior, with no project context or execution feedback. We evaluate every output with 630 hidden behavioral checks and 511 Rector-detected modernization findings. We compare against two baselines: the unchanged originals and the rule-based tool Rector. Often, the answer is no. Untouched, 83 files already pass every check; the best LLM leaves only 59. Each model breaks 32–51 working files while repairing at most 10, whereas Rector breaks 7 and repairs 6. Most of this damage is unnecessary. Only 37 findings (7%) require a change under PHP 8.3, yet in compatible files with no required change, the LLMs break 36–60% (Rector: 8%). The model with the highest modernization score is no more compatible than its closest competitors. Most regressed checks come from files that no longer load at all, often because of type declarations PHP itself rejects. These are errors that need no project context to avoid. Evaluations of LLM-based modernization should therefore measure against a no-change baseline and report modernization and behavioral preservation separately.

Index Terms—legacy modernization, large language models, PHP, behavioral preservation, empirical evaluation

I. INTRODUCTION

Legacy code often keeps running after its language moves on, while looking years out of date. Modernizing it means replacing outdated constructs and keeping the behavior callers depend on. LLMs make the first part easy, but a modern-looking diff says nothing about the second.

Figure 1 shows why. Gemini 2.5 Pro adds type declarations and modern string helpers to a legacy diff method, yet the file fails one of its four hidden checks. For an unsupported diff mode, it throws an InvalidArgumentException where the original returns the PEAR error object that callers expect. Nothing in the source marks this as a regression.

Migration benchmarks study whole repositories, often with build or test feedback, or isolated functions and snippets [1]–[4]. They score the migrated code, but not against simply leaving it unchanged, and they count required and optional changes alike. We study a common intermediate setting: a developer pastes one complete file into a chat assistant [5], which sees the file's internal structure but not its callers or dependencies. We evaluate the first answer, not an agent's result after iterating on errors.

(a) Legacy - PHP 5

untyped - strpos/substr

function diff(diff,diff,mode = 'autodetect') { // Detect line breaks. lnbr="\n";if(strpos(lnbr = "\n"; if (strpos(diff, "\r\n") != false) { lnbr = "\r\n"; } else if (strpos(diff, "\r") != false) { $lnbr = "\r"; } }

// Make sure we have a line break at EOF. if (substr(diff,−strlen(diff, -strlen(lnbr)) != lnbr) { diff = $lnbr; }

// ...

LLM migration

(b) LLM-migrated - PHP 8.3

Gemini 2.5 Pro • typed signature • modern string helpers

public function diff(string diff,stringdiff, string mode = 'autodetect'): array { // Detect line breaks. lnbr="\n";if(strcontains(lnbr = "\n"; if (str_contains(diff, "\r\n")) { lnbr = "\r\n"; } else if (str_contains(diff, "\r")) { $lnbr = "\r"; }

// Make sure we have a line break at EOF. if (!str_ends_with(diff,diff,lnbr)) { diff=diff = lnbr; }

// ... }

Highlighted tokens are modernization edits

Fig. 1. Modernization of a legacy WordPress 4.0 diff method. (a) Original method. (b) Gemini 2.5 Pro output generated from the target file alone. Highlighted tokens show type declarations and modern string helpers.

Five LLMs each modernize 100 WordPress 4.0 files to PHP 8.3 under a fixed instruction requesting both modernization and preservation of inputs, outputs, side effects, and call compatibility. We run 630 hidden checks and compare against the unchanged originals and Rector [6], a rule-based modernization tool. We ask:

• RQ1: How do LLMs and Rector compare in preserving and repairing tested behavior under single-file modernization?

• RQ2: What do source-modernization scores reveal about behavioral compatibility?

• RQ3: What causes regressions after LLM modernization?

Figure

Fig. 2. Dataset selection from the 482-file WordPress 4.0 corpus. The 100 selected files contain 521 findings across 48 Rector rule types; excluding ten general code-quality findings leaves 511 findings across 44 PHP-version rule types for source-modernization scoring.

To our knowledge, this is the first modernization study to score LLM output against the unchanged code's behavior while separating required from optional changes. Under this design, every LLM ends with fewer compatible files than the untouched originals (at most 59 versus 83), most of the losses occurring in files that need no required change.