Posted on 2019-02-11 05:07:39
“What is a PHP?” Or, more commonly, “what’s PHP?” In short, PHP is a programming language made for the web, built up from the C programming language, and which uses idiosyncratic HTML-like tags (or sigils) to contain its code. The PHP programming language is mostly used server-side, which means that it runs on your web server software, which is customarily going to serve HTML to your visitors.
PHP initially stood for “Personal Home Page.” Because that pretty thoroughly constrained the meaning and desirability of using the language for general use, the language now stands for “PHP: Hypertext Preprocessor”. This is what’s called a recursive acronym (a name that contains the name). Nerds love them.
What is PHP used for? Basically, anything that you want to do on a web server, you can do with PHP. Make a blog? Yep. Create a full fledged software-as-a-serivce application? Absolutely. Write a little script to process some data in a few seconds? PHP is great for that. Write a complicated set of scripts that accidentally becomes a successful software business? PHP is used like that a lot.
If you don’t trust me, the PHP website lists the following uses:
I’m not so sure I’d encourage the last bullet point, but it is possible. But the first two are common and good reasons to use PHP in 2019.
This leads to one important and unavoidable fact…
There are a lot of reasons to know and love PHP, probably the most potent and valid of which is this: it’s used and runs EVERYWHERE the web does. Your cheap little $3 per month hosting account may let you run a web application in Python or Ruby if you shop carefully. But it’ll definitely run PHP. This means that you can count on it wherever you are.
And because it runs everywhere, and is easy to get started with, a lot of very popular software is written in PHP. WordPress is the example that’s both largest and most familiar to me, but tools like Joomla, Drupal, Magento, ExpressionEngine, vBulletin (yep, that’s still around), MediaWiki, and more are all running PHP on the server.
WordPress proudly boasts that it powers more than 30% of the internet. You don’t need to even trust that fact to realize that a lot of the internet must be using PHP if that fact is even conceivably true.
PHP does HTML rendering and programming easier than almost any other language. So it’s pretty simple to change HTML to PHP. Just change your
file.php, add a bit of dynamism inside some
?> tags. Most web servers will have already been configured to take care of the rest for you. It’s so simple that almost anyone can get started without a need for much more of an understanding of programming than this. Because PHP is so friendly to cut your teeth with, a lot of bad code is written in it.
Once you realize that most bad PHP is written by novice programmers, most of the fear and hatred of PHP you encounter in the world comes from one other essential problem: PHP has never had a grand design with a visionary idea about why it was the perfect language for your web server. Instead, its the result of wide collaboration through an open process which serve as a crucible through which any good idea — and a few bad ones — must pass.
And bad ideas can make it through that crucible. The most popular example is that PHP 5.3 — separately widely regarded as the first modern version of PHP — introduced the
goto statement, which is generally either scoffed at or thought an easy source for errors.
Similarly bad thing in PHP that have resulted from the process through which the language has grown: object-orientation was first implemented as a flawed and limited concept, the standard library is full of inconsistent names and parameter ordering, and (in an example that recently got a fair amount of attention) the
:: token is called by the interpreter by the inscrutable-to-English-speakers:
But today, OOP is fully-realized in PHP. Few languages have as much Java-like OOP practice than PHP. What’s more, unlike Java, PHP has a single and widely-love package manager, called Composer. It was very good, and so the ease of pulling in other well-written and well-maintained libraries in PHP is nothing to be trifled with.
But those thing said, PHP is evolving in interesting ways. It’s growing toward being a pretty fully-featured Java-like (for better or worse) object-oriented language. And much like Java, it’s gaining easy abstractions for functional programming — arguably the current hotness. It’s also growing a pretty awesome set of tools — PHP loves Composer, and for good reason — and a commendable effort to make all of these large open source projects in PHP work a little bit better together.
Oh, and we shouldn’t forget the current hotness: speed gains PHP has made in the PHP 7 series of releases. This is widely regarded as having been initiated by the HHVM coming out of Facebook. For a short time, there was a risk that the speed of the HHVM would fracture the PHP community. But it didn’t. Instead PHP just got so much faster that people have mostly forgotten that the HHVM exists.
If you’re deciding what cool new technology to use, a thing I think often gets to little attention is what’s its like to come to terms with the language. What’s it like to learn PHP? PHP tutorials are common and often quite good.
One downside of PHP’s popularity is that you can find some not-so-good training from people who don’t know enough about what using the tool is really like. Or who last were following “best practices” that were current a decade ago. But on the whole, that’s rare-enough that I don’t think it should discourage you. Finding out a practice you’ve used for a few months isn’t great is rare, and not a huge problem.
A lot of people new to programming are looking for very general face-offs of languages. So, here they come. All the languages I’m going to write up here have the following traits in common with PHP:
Active Server Pages started life as a closed-source Microsoft language for web programming. It was pretty directly comparable to PHP, but ran in Windows Server environments. That was replaced by ASP.net. Which has now been replaced by ASP.NET Core. The latter two are now open-source languages, like PHP is. And I’ve personally never written a lick of ASP, in any variation.
I would favor ASP if I used and loved Microsoft servers. Otherwise, give me PHP please. The size and scale of communities are not really comparable.
The last language that makes sense in a one-to-one comparison with PHP is Python. Python is used in many more contexts than web development (it’s also very popular for statistics and data analytics). It’s also one of the more stable and well-designed languages around, in popular consensus.
I mentioned at the top that there was a lot of similarities with all prior direct language comparisons I made. But if we drop those constraints, there are tons of other languages we could compare. So to briefly touch on a few:
Again, that’s all I feel like I’ve got enough context to touch. But there are even more options you can consider. But that’s the end of the specific alternatives I’ll consider to PHP.
Given those comarisons, why use PHP? I’ve enumerated some of the things that are bad about PHP, and I feel some of them regularly. Needle and haystack inconsistency in search functions bites me at least once a month when I’m quickly doing something without autocomplete.
For a true and complete greenfield project, with no need to interoperate with any other system, or need to run in any arbitrary environment, with no existing expertise on the team, I’d think pretty deeply before I recommended PHP. Python really appeals to me in that scenario. But those are a lot of caveats. There are great reasons for even a fresh greenfield project to be written in PHP.
Any modern web language can help you make good websites and apps. And every one of them has features that aren’t ideal. PHP, like any of them, requires you to truly understand its trade-offs for you in your project to determine whether or not it makes sense for you. But for me, personally, I continue to find that it’s possible to be — as Keith Adams put it in a great talk — “shockingly productive in PHP.”
If you’ve got a team of Python programmers, write your application in Python. If you’ve got a cofounder who knows Java, write your SaaS in that. The personnel considerations of software should always outweigh the languages ones.