DEV Community

Cody Crumrine
Cody Crumrine

Posted on

PHP is still awesome (even though it's Awful!)

When I got into web development PHP was the default. It's what the web was built on. (To be fair - it seemed like half the web was WordPress). LAMP was the defacto stack - and you were expected to know it.

Since then PHP seems to have fallen out of style hard. I still work on a SAAS product with a mainly PHP back-end, and often have to answer "why PHP?" The truth there is that it's been around since that was the standard and there's no meaningful reason to change it (at least it's not Ruby!) But it got me thinking - are there scenarios where I'd still reach for PHP first today? Yes.

Now I'll still be the first to roll my eyes and say PHP is "awful". It's got no shortage of annoyances. Two of my favorites are:

  • The type juggling! Being a loosely typed language is enough to turn a lot of people off in it's own - but PHP seems to make some exceptionally unintuitive decisions. And undefined variables? Meh, let's just throw a warning and give it a try.
  • The most inconsistent function names and signatures I've ever seen!

(Go ahead and share your favorite gripes in the comments, we'll all have a good chuckle)

But here's my humble list of things I think are really great about PHP.

Web First
PHP was designed for websites. It has the request/response lifecycle built into it's DNA. Query params and request payloads are available in super-globals. STDout is the response by default.

In any other language I've used to build a web site/app I start with importing the right package/library to run a webserver. I don't have to do that in PHP.

Yes, that means I need Apache, nginx, lighttpd or similar. But it also means that I can write code pretty oblivious as to which one of those is in use. It also generally means that each request will be served in it's own thread.

In my experience there's a lot of boilerplate to serve content over http in other languages that's just "already there" in PHP.

Easy to work with APIs/Databases
I do a lot of work in the data integration space, and PHP makes it pretty easy to talk to other services.

Using curl is simple and nicely structured (if you don't mind looking up a lot of flags) and Oauth is a breeze, so REST APIs are pretty easy.

PHP's built in SOAP client is surprisingly good to (considering how much I hate working with SOAP APIs) - just point it at a valid WSDL and every method is defined for you.

Connectivity to most of the popular relational databases comes out of the box - with more available with right drivers.

Also, PHP has been ubiquitous for long enough that msjor platforms offering an SDK for their API will include a PHP variant.

Easy to Hire/Train
Again, PHP has been so popular for so long we have no trouble finding developers who are comfortable with it (even if they say "well I prefer python but...)"

But I've also had several people who are right out of college - which seems to mean they know either Java or C++ and for some reason CSS (weird mix... I'd like to see these curriculums). I've never had much trouble getting them spun up on PHP.

Some folks will point out that the ease to jump into can be dangerous (a lot of people trying to walk before they run - and with the aforementioned loose types). That's true, and it's a way JS and PHP seem similar. But in a setting with good mentorship it's been an asset to us.

So when should I use PHP?

Here's a few examples of times I would reach for PHP first.

  • Writing a RESTful API.

  • Writing a back-end that needs to interface with a lot of different platforms and APIs.

  • Any web app that needs to serve dynamic content from a DB but does not require any real-time interaction between users (like a blog or a forum).

  • An app that I want to be easily "moddable" or have a "plugin ecosystem". Though NodeJS is a good contender here to.

So... Gimme your thoughts! What did I miss that you love or hate about PHP. Is it dead? Let me know. ; )

Top comments (8)

Collapse
 
buphmin profile image
buphmin

PHP has it's place. It is a good all round scripting language. Really you can use it just fine outside of web as well. I like the fact, as a scripting language, it has strict type checking at all. The pros/cons of strict typing can be debated, but I certainly prefer having it.

Performance of PHP 7+ is quite good for a scripting lang. Based off what I have seen it is the fastest interpreted language (feel free to correct with links). JS doesn't count, it runs with a JIT. What this means is performance is still bad compared to any pre/JIT compiled lang. But honestly it's good enough for most cases.

PHP is not dead, and will not die anytime soon. It's simplicity and flexibility as an OOP lang makes it useful for smaller projects that are not performance intensive. Also wordpress. And wordpress again. Last the PHP devs seem to be taking hints from the community and driving the language in a modern direction.

Collapse
 
the3rdc profile image
Cody Crumrine

"Last the PHP devs seem to be taking hints from the community and driving the language in a modern direction." Amen to that. PHP has made some major changes in the right direction over the years. Definitely not stagnant.

Collapse
 
sonyarianto profile image
Sony AK

I love PHP and still using it now in work and in personal projects. PHP is not dead yet and still many upcoming features in the progress. Maintainers are active. I think PHP will be dead if all PHP maintainer team member are dead.

Evidence of active are:

Collapse
 
the3rdc profile image
Cody Crumrine

I agree wholeheartedly. It certainly hasn't been abandoned. I see progress with every new version.

Collapse
 
sonyarianto profile image
Sony AK

yes right, vanilla PHP + Symfony routing component + Symfony twig component + any NoSQL database + memcached are sweet, no need framework

Collapse
 
falcon721 profile image
falcon721

Hello.
How are you?
I work in china, I have a great team, we are senior team, we are growing in our business
now we want to work on Upwork site
but unfortunately, Upwork usually suspend Chinese
it's our trouble
we need someone to create Upwork account and run it for our team
we will pay for it
we can earn money lots a month
every month we will pay it, only what we need is Upwork account
thanks for your reviewing my suggestion
I hope we can have a good friendship with each other.
If you agree with my suggestion, please give me your slack or skype ID
Best regards

Collapse
 
the3rdc profile image
Cody Crumrine

Boy I sure would love money lots a month...

Collapse
 
falcon721 profile image
falcon721 • Edited

please send me your SkypeID or mail address.
Let's discuss about our deal.