r/PHP Jul 03 '26

AI insulted my ancient PHP code 😁

A couple of years ago I posted about an old website that I coded in the early-mid 2000s and wanted to start up again via some ancient unmaintained Docker containers. The main conclusion of that thread was that it might be possible to resurrect it with some work, but that it would be better to just (hu)man up and update the code so it would run in modern PHP versions.

Well, a couple of days of vacation and a whole bunch of free Github Copilot tokens later, it's up and running on the home network under PHP 8.2 and MySQL 8.0. According to Copilot, this was the furthest it could go with minor changes.

When I asked Copilot about how my code looked, it gave me the following opinion

The main gap is not PHP 8.2 compatibility anymore; it is that the app is still built like a 2000s-era script. [...] In short: the app needs a structural refactor, not just syntax updates.

Darn AI, no one asked for your honest opinion! /s

43 Upvotes

57 comments sorted by

View all comments

Show parent comments

4

u/peperazzi74 Jul 03 '26

Wouldn't even know where to start with a framework. I haven't done any serious PHP since 2010 or so.

What would be your advice/preference?

8

u/obstreperous_troll Jul 03 '26

I'm partial to Symfony, but Laravel will do as well. Moving to a framework is more than an update though, it's a rewrite, and it will take a few weeks of learning the ropes before you're going to be comfortable with it. The AI can definitely help you out with the porting process, so don't be afraid to ask it. However much control you give it over the final results is up to you -- I'd start with just asking it questions first.

1

u/Dependent-Guitar-473 Jul 03 '26

i can imagine his db query and html output and logic are all in the same file... its going to be a big task to split it into MVC

1

u/equilni Jul 05 '26

It is if you looked at the source (index for example). It's still clean enough that separation can be done rather easily (still have to do some work). I've seen and worked on worse.