DEV Community

loading...

Why does PHP get so much hate?

koreymoffett profile image Korey Moffett ・1 min read

I’ve noticed online a lot of times when someone asks a question about php or if they should learn php it’s always met with no or why would you learn that, I’m curious why that is.

Discussion

pic
Editor guide
Collapse
andreidascalu profile image
Andrei Dascalu

I've got 17 years of PHP under the belt and there are some points to be said:

  • PHP is a victim of its popularity. With lots of sites across the internet in PHP, there are many old versions there, each bearing significant differences, enough to be a pain to developers migrating between projects
  • Wordpress. Just look at it. Its development is soundly grounded in early php 5 versions. If you have any format programming training, looking at the Wordpress API will leave you wondering if those guys simply hated OOP or any kind of engineering best practices (spoiler: no, but PHP became OOP-ish fairly late for Wordpress to change). Many say that Wordpress is what helped PHP survive enough to become a real language in the later 7.x installments
  • inconsistent API. The core PHP API has always been messy (tons of 'utility' functions thrown around, inconsistent parameters, interfaces you can't implement, etc)
  • it's a web language but ... needs a third-party server to run? That's the biggest pain and WTF for me. At some point PHP got a server as part of its platform, but with a big "don't use in production" sign. Just about any language comes with some webserver implementation as part of its core platform (Java, nodejs, Go, Rust, you name it). Some still recommend using an efficient reverse proxy / balancer (eg: node) but for most others you get it out of the box. PHP has FPM but still can't function without Apache/Nginx. Rubbing salt on the wound: in today's cloud-native world, you can't containerize PHP to simply work with an Nginx ingress or Cloud LB, you still need to package another damn webserver. Ok, nowadays there's a nice multithreaded application platform (Roadrunner) that removes the need for fpm & nginx.
  • the fact that some many radically different versions still live make it difficult to progress as a developer and easy to get trapped in bad code world. Myself as a job candidate keep underlying that I 'support' only PHP >= 7.3, I won't take jobs developing PHP for older versions unless their primary medium-term goal is migration.
Collapse
shayneoneill profile image
shayneoneill

The "needs a third party server" isn't a negative. If theres one bitter lesson to be derived from the rise and fall of Nodejs as a backend webserver, its that servers written in scripting languages will never compete with those written in performant languages like C, Rust or Go. Theres a damn good reason why the rails or django people usually put their stuff behind something like Nginx or Apache. Like yeah, most of these things have native webservers if you want them. But you shouldn't, and nobody with any experience does.

I'm not defending PHP as a language, its atrocious, but it'll flatten any of the JS frameworks for scaleability and performance simply by virtue of the fact it doesn't even try to be a web server.

Collapse
andreidascalu profile image
Andrei Dascalu

there's a big different between nodejs's implementation and php. Namely that in a cloud native environment, you can let the ingress controller (effectively nginx or similar) to perform the same task. It will perform the same as on a local machine with an nginx in front of it, since it never needs more than your regular reverse proxy.
FPM doesn't work with that. It needs its own dedicated nginx/apache and doesn't work with pure reverse proxies or load balancer (which are not themselves aware of physically present files).
In this context, while PHP/FPM/Nginx can theoretically scale better on a bare metal environment, it doesn't do as well in a cloud-native environment.

Collapse
juslintek profile image
Linas

Well, now days you can use openlitespeed with its mod_php, a better alternative to php-fpm and nginx or apache mod_php. :-) Also you can use swoole :-) To make it multithreaded and run as a server on its own. As well there are other implementations. As well you can write your own requests handler and run it, for example, like in laravel php artisan serve. There are many solutions, just need to investigate. But yeah something that is implemented to work out of the box for production, yes it doesn't exist. That's why we have web servers. :D

Collapse
andreidascalu profile image
Andrei Dascalu

Well, the question was why php gets a bad rep. Think about what you just said. Roadrunner aside, you need to go to third party tools just to get things running.
Nobody ever said there's no way, I also listed some, you did and so on. But there's a lot of legacy out there, lots of inconsistencies in the language and despite all the new stuff that's nice and all, you also need to be in a position to use it.

Collapse
yellow1912 profile image
yellow1912

For server:

  1. You can use PHP-PM to replace PHP-FPM: never tried it, but look very promising (github.com/php-pm/php-pm)
  2. You can implement simple, performance server with Swoole extension (I don't recommend it for normal website, but I created simple tcp/http log servers with Swoole and Clickhouse to record billions of logs per month just fine on a small instance)

Your argument with versions can apply for ALL languages out there. There will ALWAYS be apps that run with code from 10 or 20 years ago. In my experience, the salary for those (boring) jobs taking care of old apps can be way better due to the limited number of capable resources.

Collapse
andreidascalu profile image
Andrei Dascalu
  1. You can use php-pm. Like I also mentioned, there's also Roadrunner (slightly better performing than php-pm). PHP-PM has the advantage of working reliably with more PHP versions, but the thing is, PHP is great in newer versions. I'm not bashing on PHP for that, it's a moot point to argue with someone who's seen php 5 code and working with developers who spent years on php 5 and can't bring themselves to 'upgrade' to newer versions and worse -> perpetuate old coding ways.
  2. Sure, Swoole is great, but again, it's one of the modern tools. I really dare you to bring Swoole to Wordpress though.

Well, yeah, but it's only with PHP that you see so much legacy still in production. The only other language with the same weight is Java. It's no to say, for example, that you can't find applications in that are legacy and running, but the special case of PHP is that literally ALL CMS in PHP have their bulk of code written legacy-style. And then people use them to start new applications today and the developers working on them won't be exposed to good practices.

Thread Thread
yellow1912 profile image
yellow1912

There are modern cms out there, problem is that they don't have enough usage, plugins, and integrations to beat WordPress. That and the fact is that most WordPress users do not care about what's under the hood.

It's kinda unfair to blame the incompetence of the CMS on the language itself though. I think PHP has longer history than some languages and thus have more apps with legacy code. When you have millions of business depend on you, you cannot make radical decision to break things left and right.

Thread Thread
andreidascalu profile image
Andrei Dascalu

exactly, so you have an environment the promotes legacy and bad practices. Also, while Wordpress "users" don't care what's under the hood (users or customers never do), Wordpress developers (as in developers customising WP for use cases) also don't (not really). But they have contact in the sense that sooner or later you use hooks, you need to debug - and the code that you see models the code you write. And then the code you write then becomes part of your style. And then, at some point, you come into contact with people who write modern code and .... that builds the reputation of the language.

Thread Thread
yellow1912 profile image
yellow1912

Right, I do agree. I have another perspective though, perhaps unique to my situation: when a client contacts you and asks you to do something related to .net or java, they know they must pay big bucks. On the other hand, clients for PHP work normally have a much lower budget, they always look for quick, and cheap gigs. That comes back to bite them in the future though because you cannot have great developers putting a huge amount of care into the project. You end up with quick hacks that are full of holes.

Also despite all it's faults, I find it very difficult to convince a client to try out any other solution. Even knowing all its shortcomings, the clients always want to use something that is popular or recommended by their marketing guy, or that they are familiar with.

I'm not blaming anyone for this of course (perhaps it's everyone's fault?). It's just an observation.

Collapse
dakujem profile image
Andrej Rypo

I suspect there's multiple reasons.

First, I believe those haters never tried anything like PHP 5 and come from the preceding era. Honestly, versions since 5.3 are decent.

True, there is much legacy in PHP and quirks here and there. But man, jus look at JS. It's a ridiculous mess, and how popular it is nowdays!
PHP is becoming more awesome every year with every new release.

Second, I think there are many devs that started with PHP, and we know how shitty our code was in the beginning. (Those who do not yet recognise this, no worries, just wait a couple of years and then look back.) And since php is very flexible, it allows for pretty bad design errors. So I think there is a lot of bad code there written in PHP, that gets attention. People who see that will generalize and blame PHP, but it's not the language's problem.

And the worst problem of all is that PHP allows for the shitty code to actually work.

Collapse
christiankozalla profile image
Christian Kozalla

Hey Korey, I have noticed that, too. A few months ago before I got to know PHP. I am self-taught in HTML, CSS and JS for only about a year...so can't really judge.
My only guess is, that PHP is pretty old and paved the way for dynamic websites earlier as a server-side scripting language. But with modern webdevelopment and the rise of frontend frameworks, scripting is done more on the client-side with JS. Plus, JS move to backend server-side with node.
Here in Germany there are many job offers requiring skills in PHP since many apps still rely on it, so there's no hate at all!

Collapse
leob profile image
leob

I think those views are largely based on the old-fashioned PHP of a decade ago, which was a "hackish" cobbled-together scripting language with an inconsistent API, no proper module system, and so on.

Modern PHP (version 7, and soon 8) is lightyears beyond your granddad's PHP in terms of performance, modularity, features (OOP) and so on.

Couple that with a framework like Laravel (as opposed to the spaghetti code of Wordpress) and you have an absolutely powerful and elegant development environment which can (even in this era) compete with the likes of Ruby on Rails, Python/Django or Node/Express.

Anyone who thinks PHP is dead and old-fashioned, think again, it's alive and kicking, and it's used a LOT.

Collapse
ricardosawir profile image
Ricardo Sawir

Hi Korey, I love PHP, on the contrary. For your info, it's a backend language, that can be embed with your HTML code.
May be some hate just because of the word of mouth effect. When I first started programming, I also met with that PHP haters. But ironically, I got blessed, also thanks to PHP. Many people still use PHP. If not, there wouldn't be PHP 8.

P.S. I create an e-book about 50 useful tips when using PHP. May be you get benefits from this? gumroad.com/l/50phpcode/blackfriday

Collapse
shayneoneill profile image
shayneoneill

Its a cultural thing really. Working on PHP tends to mean your working on Wordpress. And wordpress is a lousy piece of ancient software. Theres no joy in that stuff, its the burger flipper job of the codemonkey industry.

To make it worse, wordpress's evolution traded one set of bad ideas (Old PHP, barely structured, no separation of concerns, etc) with a horribly convoluted Java inspired hell. Even 'simple' frameworks like Laravel inevitably end up forcing you to buy into Symphony (if anything just to swap out the horribly written ORM for something a bit more capable like doctrine) and from there things get bureacratic and painful. Its just not a fun way to live.

Unfortunately JS isn't much better. Its fad driven, prone to abandonment and incapable of learning from past mistakes and lots and lots of abandoned libraries , but outside of js, trusty old Rails still works fine, Django is marvelous and on the ascendent (which is sort of amusing to see it reach fad popularity , as pythons actually a pretty old language), Java sucks, but its still a solid choice if you need access to some extremely complete enterprise libraries, and Go and Rust are both proving themselves as excellent choices for the speed demons out there.

Collapse
wrldwzrd89 profile image
Eric Ahnell

The accumulated legacy from PHP 4.x is where most of the hatred comes from, even though it's no longer supported, nor is its successor 5.x. PHP definitely has gotten flak for quirks, but there has been huge improvement since 7.x at cleaning the worst of them... exception handling comes to mind as needing and getting more love in v7. Plus, PHP still has plenty of applications using it... WordPress is often used as an example, but don't overlook MediaWiki, the foundation behind Wikipedia and many other topic focused wikis.

Collapse
aleaallee profile image
Alejandro esquivel

People are still stuck in the 5.4 era when PHP actually sucked. I started learning PHP after 7.0 got released so I didn't had any issue with it.

Collapse
yellow1912 profile image
yellow1912

Developers in general are strange human creatures. People often users terms such as nerds to describe us for a reason. We are usually over-passionate about certain things (hate or love), and are often closed-mind (surprisingly). Once we hate something, we never look back.

PHP was an easy blame target for many security and performance issues of the web, mainly because it is:

  1. The most popular language for the web
  2. Easy to pickup (but not easy to master, no language is easy to master)

I think one should learn PHP if:

  1. They want to look for job (not the best paying, but always in demand)
  2. They are familiar with and like C-style syntax
  3. They want to work with a stable language (no sudden change of syntax, or major issue upgrading to new version)
  4. They like the a performant scripting language (with plugin, PHP can also do async like Node and Co routine like Go). The new JIT feature in PHP 8 should open doors for Machine Learning and many other applications with PHP as well. We may even see a PHP based server someday.