Canonical: https://botbento.com/usecases/modernize-a-legacy-php-file-with-an/
Format: Markdown representation of the public HTML page.

# Modernize a legacy PHP file with an iterative coding bot

[Coding](https://botbento.com/usecases/coding/) · Intermediate

Reads one legacy file, proposes a modernized version, runs the tests, and opens a draft patch for review

A bot that takes a single legacy file, rewrites it for a current runtime, then loops on failing tests until the change is stable. It shows the diff and test output instead of merging anything itself.

## Quick answers

**What does it do?** Reads one legacy file, proposes a modernized version, runs the tests, and opens a draft patch for review. Result: Diff and test report for review.

**What does it need?** Tools: GitHub, Terminal, Chat. Intermediate: some setup. The prompt includes an approval step.

**How do I run it?** When you ask: User points bot at a file. Copy the prompt below into a bot in BotBento.

## How it works

1. When you ask: User points bot at a file
2. Then: Rewrite, run tests, revise
3. Result: Diff and test report for review

## Prompt to start with

```text
You are a legacy-code modernization bot. When the user points you at a file, read it and its tests, then propose a modernized version. Run the test suite, read the failures, and revise your change until tests pass or you are genuinely stuck. Report back with the diff, the test output and a short note on remaining risks. Never merge, push to a shared branch, message teammates or delete old code without the user's explicit approval.
```

## Tools it uses

GitHub, Terminal, Chat

## Works with

BotBento

## Tags

legacy-code, refactoring, php, testing, code-review

## Source

[When Modernization Breaks Working Code: A Study of LLMs on Legacy PHP](https://news.ycombinator.com/item?id=50330033) — Hacker News · checked 2026-11-13

Summarized in our own words. Any results described there are the authors’ own, not measured by BotBento.

By BotBento Editorial · Added 2026-11-13 · Updated 2026-11-13 · [Suggest a correction](https://botbento.com/contact/)

## Related use cases

- [Legacy code rewrite support with behavior mapping](https://botbento.com/usecases/legacy-code-rewrite-support-with-behavior-mapping/) — Map old behavior first, then draft refactors for engineers to review
- [Minimalist code implementation and pull request review](https://botbento.com/usecases/minimalist-code-implementation-and-pull-request-review/) — Write less code by reusing existing repo components and catching breaking changes early
- [Fix bugs from issue reports with tests](https://botbento.com/usecases/automated-test-driven-bug-fixing-and-pull/) — Reproduce an issue, write a failing test, patch the code, and prepare a PR for review
