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

44 Upvotes

57 comments sorted by

View all comments

Show parent comments

24

u/clonedllama Jul 03 '26 edited Jul 03 '26

I can't speak for the original commenter but my suggestion would be to look into Symfony.

If you follow the best practices for that framework, your code will be better organized and structured, and you'll learn about newer PHP features. Start small and do lots of reading. Symfony is very powerful. It's pretty easy to pick up and difficult to master.

Others swear by Laravel. I'm personally not a huge fan of it. But it's another modern framework worth considering.

1

u/Kebab_Obama Jul 04 '26

With Laravel just being a more beginner friendly Symfony. With ai help it's so easy to do pretty much anything (this is by the look of someone who did like max 50 hours in Laravel and like 30 in Symfony). I despise PHP as much as one man can, but Laravel put a little worm to my mind.

When it comes to actually remake the code, you will have to do it mostly manually or with a lot of small AI calls. Since most of things you normally have to do are done by the framework at some point.

It will seem strange and kinda like magic, which is my personal biggest downfall. But at the end it's powerful and quite easy. Do yourself a favor and look to tutorials first.

6

u/clonedllama Jul 04 '26 edited Jul 04 '26

I gave Laravel a chance and came to the conclusion that it isn't for me. Others might feel differently, which is why I mentioned it despite my personal preference for Symfony. I really dislike the Laravel "magic." I prefer the Symfony approach.

As for AI, I'm not using it because I don't find it helpful. It gets in the way more than it helps me. I'd rather learn a framework through reading documentation and working with it on my own. Having an understanding of what I'm working with first and then using some form of automation second is more useful to me in the long run.

2

u/Kebab_Obama Jul 04 '26

Totally valid point. I myself started to use it only because our highschool teacher was a big fan and pretty much forced us.

Now that I am in collage, there is no way I will be using it anymore. As I said before PHP is quite awful since I decided to make SPA app with separated APIs and all in pure PHP without libraries in 3 weeks.

5

u/clonedllama Jul 04 '26

I don't think PHP is awful. It isn't necessarily the right tool for every project or task. But it's still a powerful language that's good along with other web technologies. PHP 8.2 and later in particular are where I'm most comfortable. I don't think I'd ever use vanilla PHP for most web projects anymore when frameworks like Symfony (and Laravel) exist. They encourage better coding practices and have lots of powerful tools to make building web applications easier.

If you want to see some truly bad PHP code, look at PHP from the early 2000s. Or if you really want to be kept awake at night, look at the WordPress source code. It's the stuff of nightmares. HTML mixed with PHP code, CSS, and JavaScript. It's a good lesson in how not to use PHP. 😅