Why PHP still sucks, even if you like it

There is some discussion going on about this post. So here is what I think of it.

If PHP is the first programming language you've ever learned, you maybe feel comfortable with it because it is easy to get things done, it is easy to deploy copy to a webspace and forgives you anything which is important to know as an upcoming programmer. Short: It feels just good. But if you will ever get in the real world with real problems, you will notice that something isn't quite right. Something started to get weird, it's like missing an important thing, but you don't even notice what it is. After some time you get frustrated and ask yourself what the problem is. Maybe you start thinking about and try a language you probably flirted with in the past, but you never had the time to look on beside your extensive Wordpress template hacking. I saw enough people trying other languages like Python or Ruby after years of PHP development and they were so happy to have a real language without all the problems they were struggling with in the past. I was one of that guys and thought "Wow, how fun coding can be"!

I think nowadays for most PHP people it feels like using a walkman. It kinda works, but the sound is crap. But hey, this is the one I grew up with, so lets stick with it. Maybe it's an argument for some kind of cool old hardware, but not if you want to write good (web) applications. There is no place for nostalgia.

After the initially mentioned post, some people started to write blog posts with titles like "PHP Sucks! But I Like It!". There are some reasons mentioned in this post, why PHP is still useful but they are not the best ones. Because they are not an advantage of the language PHP. The reasons why PHP is widely used in that way are more historical than technical ones.

Since I am a Ruby guy, who switched from PHP years ago, I will give examples from the Ruby world.

PHP is best in HTTP. Tell me tangible parts where Ruby (or Python) is not, but PHP. At least Ruby has also built-in HTTP Methods. And it's not the benefit of the language PHP that there are many CMS like Wordpress, Typo3 and all the rest. In fact, it's the opposite of that. Because PHP is so ugly, unmaintainable and inconsistent, no one wants to write plain PHP to build web apps or frameworks. If you can have one or two very good and effective frameworks, who's in need for just another crap CMS which covers only 80% of what you initially want to do, where the other 20% are a pain in the ass to implement against that CMS?

Ruby got famous (at least in the western world) with the rise of Ruby on Rails in 2005. Thats the main reason why people are often confused about Ruby as an independent programming language. People started to write Ruby because they started using Ruby on Rails. And no one felt like there was time to pimp the Ruby language with some stupid things, which are only needed for the specific web domain.

PHP started as some kind of "Personal Home Page" tools and evolved to a "language" with nifty things like registerglobals, safemode und magic quotes, which as far as I know aren't really good features of a native web programming language. Also the whole OOP thing was introduced after some years, which is a big and still noticeable issue today. Maybe there was no better alternative back in 1998 and everyone started to use PHP to get things done in web. So yes, PHP was a good choice for fast coding web tools, but that was 14 years ago.

PHP is for fast web development. Given the fact, that it is really hard to measure the speed of development, I will give a simple example. Sinatra is a DSL for fast developing web applications. It's written in Ruby. Take a look at it and tell me: How will you be faster with anything else? There are some things like Sinatra for PHP. So have a look at the example (I know, that the programmers view doesn't count for a customer, I will get to that later):

How a Hello World web app needs to look like with PHP:

// Fat-Free Framework http://bcosca.github.com/fatfree/
require_once 'path/to/base.php';
F3::route('GET /','home');
  function home() {
    echo 'Hello, world!';
  }
F3::run();

How a Hello World web app should be with Ruby:

# Sinatra http://www.sinatrarb.com/
require 'rubygems'
require 'sinatra'

get '/' do
  'Hello, world!'
end

Now tell me, what is better to read and therefore better to code, maintain, extend? This is a real example for differences on language level. And this is what developers see all day long.

With PHP it's easy to deploy. Well, all I have to say is: What can be easier then doing a

git push heroku master

For everything else on that topic, read the initially mentioned blog post, which is quite more detailed than mine.

Customers want to have PHP because developers and hosting costs are cheap. If the price is the only thing a customer cares about building an application, then you threatened him in a bad way or he needs some serious enlightenment. Do you remember when you bought the cheapest car, phone or tv? No? Me too. So think about that, if you want to use it as a reason for something in the future. Between "doing the job" and "solving a problem in a efficient and sustainable way" lies (at least for me) a slightly different approach to deal with a customer. Sure, maybe it will be more expensive sometimes, but the product is even better. If you can't make your customers understand that, then you failed before you even started coding PHP. Beside that, everyone would work for more money, if there weren't so many middle-class developers beating down the price. Also costs for hosting Ruby will (or are already) be adjusted to the same level of PHP. This is also a historical reason, why every provider offers webspace with PHP and nothing more. It's simply there for a longer time.

Are there reasons left to stick with PHP?

If yes, let me know, if not, go ahead learn something new to built a better web.

Try this ones and see which language fit's your needs without being stupid:

http://learnpythonthehardway.org/

http://tryruby.org/

or if you are brave: http://nodejs.org/