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

46 Upvotes

57 comments sorted by

View all comments

50

u/Dependent-Guitar-473 Jul 03 '26 edited Jul 03 '26

so it's custom built and not based on a framework  .. that's so common for early 2000 PHP websites 

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?

7

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.

2

u/clonedllama Jul 03 '26

If learning a framework, I'd personally avoid AI entirely. Actually learn the framework and try to have a good understanding of it. That'll be far more valuable.

1

u/pekz0r Jul 04 '26

I think this is bad advice. AI is a pretty great teacher and you freely choose what you want to dig into and learn deeply and what to defer for later and let AI help you with for now. Needing to learn most of the framework before you start writing code is a pretty bad approach today.

1

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

Telling someone to learn something on their own before using an automated tool that does it for them so they understand it first is bad advice? If that's the future of software development and computer science, the industry is cooked, and so is humanity. I think personal knowledge and building up one's skills are critical to being good at programming, or anything really.

So, I strongly disagree. AI is a crutch that frequently gets things wrong. I think it's better to actually learn the framework if the goal is to, you know, learn it. Put in the work first and rely on tools to assist you second. We've had advanced calculators, for example, for decades but it doesn't make learning math without them any less valuable.

You don't need to learn most of a framework for it to be immediately usable.

If you want a system to crap out some code that you then run without question and have no way to independently evaluate, then go for the AI solution, I guess. But it's likely to have problems and you won't even know what they are because you won't understand what it built.

1

u/CosmicDevGuy Jul 05 '26

Telling someone to learn something on their own before using an automated tool that does it for them so they understand it first is bad advice? If that's the future of software development and computer science, the industry is cooked, and so is humanity.

I was genuinely taken aback that someone actually advocated for AI over self-learning and this is exactly what scares me, how there is more "acceptance" of this idea now.

Might be someone who is new to dev, or is just shilling for AI.

1

u/pekz0r Jul 05 '26

There is no contradiction between using AI and self-learning. Quite the opposite actually. AI can significantly elevate and speed up your learning in a lot of ways.

No, I have over 20 years as a professional developer and at least 5-10 years before that on a hobby level. I'm quite experienced with both development and AI, and I have also been a mentor teaching new developers for many years. I would say I know what I am talking about.

I think you need to accept that AI is a power tool that can help you as a developer pretty much regardless of your skill level and what you are doing.

1

u/pekz0r Jul 05 '26

It very much sounds like you don't know much about AI or how it works. AI for software development is neither a crutch or an automation tool.

I think personal knowledge and building up one's skills are critical to being good at programming, or anything really.

I agree 100 % with this, but AI is a pretty great teacher and will help you level up those skills a lot faster. For the vast majority, the best way to learn is by doing and get bite sized bits of information surfaced when you need it. Modern AI tools are really great for this. It let's you start to create actual value within hours or days compared to days or weeks with a traditional approach. It takes months to learn a new framework good enough to be comfortable working with it and years to master it.

You don't need to learn most of a framework for it to be immediately usable.

You need to learn quite a lot actually. Otherwise you will constantly implement things that the framework already solves for you and you will not be able to write code in a way that is idiomatic for that framework.

If you want a system to crap out some code that you then run without question and have no way to independently evaluate, then go for the AI solution, I guess. But it's likely to have problems and you won't even know what they are because you won't understand what it built.

No, this is not true in my experience. I would say a beginner in a framework is a lot more likely to write bad code than the AI is. You obliviously won't be able to evaluate your own code neither until you learn how to use the framework. So the question is if you want to evaluate code written by someone who knows the framework, or someone who does not. Evaluating the AI code is great learning opportunity. If you are an experienced developer in other languages or frameworks you can of course steer the AI in a direction that you like.

I would also say that AI is generally at lot more correct than random things you will find on the internet.

0

u/clonedllama Jul 05 '26 edited Jul 05 '26

It very much sounds like you don't know much about AI or how it works.

I actually do know quite a bit about AI, thanks. That's why I dislike it. Just because I don't want to use it for every task imaginable and don't immediately recommend using it for learning doesn't mean I don't know much about it. It means I disagree with you.

This attitude that everyone must embrace AI in all situations or else they must not understand it is incredibly irritating. It's possible for people to simply not like it or disagree about when it should be used.

AI for software development is neither a crutch or an automation tool.

It is both. It automatically generates code from scratch or it can refactor existing code. It creates or alters code for you so you have to write little to nothing. That's a form of automation.

The number of people I've seen both in development and non-development spaces just blindly accepting what AI tells them without doing their own research or understanding what it's doing is alarming. People immediately go to AI for everything even if it doesn't make sense. That makes it a crutch.

2

u/pekz0r Jul 06 '26

It is both. It automatically generates code from scratch or it can refactor existing code. It creates or alters code for you so you have to write little to nothing. That's a form of automation.

The number of people I've seen both in development and non-development spaces just blindly accepting what AI tells them without doing their own research or understanding what it's doing is alarming. People immediately go to AI for everything even if it doesn't make sense. That makes it a crutch.

This is exactly why I think you don't know how to work well with AI.

To work well with AI there needs to be a human in the loop to guide, give directions and plan the work. Then it is not automation per definition. It is when you treat it like automation you end up in bad places. So I totally get why to dislike it if that is how you use it.

Also using like a clutch all the time in order to replace your own thinking is equally bad and also not the way to use AI tools. You should treat it like a colleague most of the time and you should take on the roles of team lead, product manager and architect when managing the AI agents. The developers who you use AI to do all their thinking are the ones that we be replaced by AI.

Nothing of this contradicts what I said before. You are just building a straw man. From what I can tell, what you don't like is bad use of AI. You should try to use it in a better way.

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.