r/webdev • u/pineappletinis • 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.
View all comments
Show parent comment
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.