r/webdev • • 29d ago

Question How warranted is the PHP hate?

I feel like there has been a lot of hate on PHP, especially after the recent blowout regarding PHP vulnerabilities that even ended up on mainstream media. I even saw absolute non-techy people bringing up PHP and talking authoritatively about how "bad" and "old" it was lol. Not to mention the AI-shills saying one should just use Claude to create one owns CMS (!!). I am also aware that most PHP hate is usually misaligned hate intended for badly managed WordPress sites. And that some people just prefer other languages or love a hatetrain.

But one thing in particular that got to me was someone who mentioned that PHP has a page with vulnerabilities listed that go back 20 years and have yet to be patched. And that if you are a dev who is in any way interested in security within one's projects, you just don't use PHP at all. It was like having only a screen-door for your house with no locks. Do other languages have similar list of unsolved vulnerabilities? What makes them inherently more secure?

I dug around to find information about other popular programming languages and frameworks and it seems like at least right now, many are being found to have vulnerabilities due to AI being used to find them. React had a critical issue about a year ago, and Python earlier this year (although they did not blow up in the press like this).

Anyway, I would like to hear from people who use PHP regularly for work, beyond WordPress and who can maybe compare it to other languages/stacks as well. Please no low-effort replies from people who last used PHP 20 years ago or just don't like it, if possible.

0 Upvotes

89 comments sorted by

View all comments

-1

u/vanderaj 29d ago

The problem with PHP is that folks who don't know how to code (before AI) end up coding in PHP. And it's horrifically bad at enforcing any form of type safety, security, or anything approaching modern web development architecture or security standards. MVC? Never heard of her. OWASP Top 10? What's that?

All that changed with AI. Adding a few key skills, Claude can create excellent Laravel and Symfony apps in next to no time, and you can ask it to secure the application properly. I'd recommend watching a few enthusiastic PHP YouTubers, and finding relevant AI skills, and you should be ok.

But hand-coding PHP? Yeah, nah, please don't.

Source: I've coded a PHP forum for 20+ years. PHP was my primary language at the time until I discovered Go and fell in love. Also, one of the co-leaders of the OWASP Top 10 for 10+ years. I recently had Claude rewrite my forum from scratch in Laravel and secure it. Modern AI is a game changer for PHP devs. Please don't hand code PHP.

1

u/pineappletinis 29d ago

Ok, this is actually a great explanation! So essentially PHP, unlike other languages allows for certain mistakes by inexperienced/bad programmers that lead to vulnerabilities down the road. Where another language would throw an exception (typing stuff for example) PHP lets is slide and that creates the vulnerability/issue? 

Out of curiosity, I’ve heard others say (generally, not PHP specifically) Claude writes inefficient/bloated code. How would you say it worked for you and do you go through the code by hand?

2

u/vanderaj 29d ago

I don't know why I ended up being downvoted, but oh well, it is what it is.

The ease of getting into PHP programming is both a blessing and a curse. You don't need a software engineering or CS degree to do it, and that means a lot of folks who've never really tried their hand at coding do so. They look at the PHP sample code on php.net, and it's really not that great in isolation. There are so many thousands of functions to choose from, and then there are all the different frameworks. Things have started to get better - most folks who write modern apps will use one of the major frameworks, like Laravel or Symfony, and they, along with PHP 8.4+, are great. Many of the things that PHP 4 or PHP 5 would let slide aren't allowed these days. But if you search Stack Exchange for coding samples on how to do something in PHP, it's nearly always pretty terrible code, and doesn't take into account the code that sits in front of you.

The code AI writes is generally well-written and understandable. The days of 100k commits and unmaintainable code are well and truly over. I know that's not what a lot of artisanal coders would like to hear, but it's the truth.

When I ask it for a feature that is commonplace today, it does a good job of architecting it and writing effective functional tests to ensure it does what it needs to do. The code it commits is easily human-readable and maintainable if you want to do that by hand.

Here are a couple of examples of tests it wrote:

it('offers the owner a link to edit their profile', function () {

$this->actingAs($this->member)->get($this->member->profileUrl())->assertSee(route('settings.profile'));

$this->actingAs($this->viewer)->get($this->member->profileUrl())->assertDontSee(route('settings.profile'));

});

it('links post and thread authors to their profiles', function () {

$thread = threadWithPosts(Forum::factory()->create(), 1, [], $this->member);

$thread->forceFill(['user_id' => $this->member->id])->save();

$this->actingAs($this->viewer)->get(route('threads.show', $thread))->assertSee($this->member->profileUrl(), false);

$this->get(route('forums.show', $thread->forum))->assertSee(route('members.show', $this->member->id), false);

});

As you can see, the code is easy to reason about and easy to maintain if you'd like to add more tests or assertions to the generated code. Nearly all the code is like this.

1

u/pineappletinis 28d ago

Thanks for explaining that in detail as well! I think the downvotes are because of the mention of AI. I would say developers have mixed experiences working with AI, some say it overcomplicates things and produces inefficient code, then I'm sure there are others who don't know what they are doing (with or without AI) who probably end up creating a mess as well. I think AI can work if it's not overwhelming people with code (which it seems to be doing for many, the point that they cannot keep up with testing due to time pressures) and has human oversight. But I also understand the hand-coders, especially those that are actually good and spent years honing their craft.