I am a software engineer at Google on the Android project and the creator of the Java testing framework TestNG. When I'm not updating this weblog with various software-related posts or speaking at conferences, I am busy snowboarding, playing squash, tennis, golf or volleyball or scuba diving. Cedric is a DZone MVB and is not an employee of DZone and has posted 90 posts at DZone. You can read more from them at their website. View Full User Profile

I like PHP

  • submit to reddit

There, I said it.

I know it’s fashionable to mock PHP for its antiquated syntax and semantic quirks, but I just like it. Here is why.


PHP is like C

This is really the main point of this post, and it’s a realization so simple that I’m surprised not more people made it. I have often observed that developers mocking PHP tend to be much more positive when I ask them about C.

“C is alright, it’s not OO but it was designed with a simple goal in mind and it does that very well. It’s straightforward and very well documented”.

Does that remind you of another language? That’s right, PHP! PHP is exactly like C. Either you like both or you don’t like either, there is no claim you can make about PHP that can’t be made about C as well, and vice versa. PHP was created with one very simple goal in mind: enabling the insertion of programming logic in web pages. And it does this fantastically well.

The absence of OO functionalities in both languages is a bit of a bummer (PHP 5 tried to address that with mixed success), but with some discipline, it’s really not hard to reach a reasonable architecture for your programs.

PHP never let me down

I write PHP code very sporadically, whenever I need to update one of my web sites or when I need to put together a small piece of web functionality that requires some programming. I am familiar with the PHP syntax but I don’t know much of its API, because I use it so rarely, so I pretty much need to relearn it from scratch each time. Whenever I need to get something done, I spend a decent amount of that time looking up docs on Google. And PHP absolutely shines in this area. It’s not just that looking up a function name will give you its API documentation as a first hit, but you can literally type what you need in English (e.g “most recent file in PHP”) and it’s very likely that you will find how to do it in just a few clicks.

You can even misspell function names (see for example the result of my incorrect query for strtime) and you will still land in the right place.

PHP is robust

I know it sounds silly considering how primitive and old the language is, but the bottom line is that code that I wrote more than ten years ago has been working absolutely flawlessly and without any changes for all that time. I don’t even bother writing tests for most of the PHP I write (obviously, I would be a bit more thorough if this code were destined to be used in a more mission critical web site). Not writing tests is not the only software taboo that I break when I write PHP: I happily mix up presentation and logic all the time. That’s just how PHP is supposed to work, and when the site you are working on is low volume and only of interest to a very tiny fraction of users, you probably don’t want to spend too much time on tasks that look overkill.

PHP’s documentation is great

It’s hard to pinpoint what exactly makes PHP’s online documentation so useful. It’s probably a mix of the content, the syntactically colored code samples, the CSS and most of all, the examples at the bottom. These are absolutely priceless and I don’t understand why not all API documentations do this.

Whether you are looking up an API function or a UNIX command, the first thing you want to see is examples, not a laundry list of its options and switches or a formal definition of its parameters. Very often, reading the example is all you need to carry on with your work and you can always read the more formal documentation if you want to use the function in a more advanced manner.

Universal support

Most Internet providers offer PHP support out of the box, so you don’t need to resort to more expensive VPS providers. I have yet to see this kind of universal support for any other language than PHP. Not even Ruby on Rails, let alone Java, is available on mainstream providers, thereby validating the claim I made five years ago that Ruby on Rails won’t become mainstream (I regularly receive emails about this article asking me this question, and I keep responding “Nope, still not mainstream”).

High reward

There is nothing more exciting than modifying a file, hitting Refresh on your browser and seeing the result right away. This brings me back to the very first days that I started experimenting with a web browser, more than fifteen years ago. Modifying an HTML file and seeing the result almost instantly hasn’t lost its appeal, and PHP is certainly continuing the tradition.

Sometimes, I don’t even bother editing the files locally and then transferring them: I ssh to my server and modify the files live. If something goes wrong, git makes sure that I can always back up my changes very easily. By the way, the combination of git’s branches and PHP is very powerful, allowing you to switch between entire web sites with just one command.


Even though writing in PHP always feels like going back in time, I’m never reluctant to doing it because I know that it will be rewarding and relatively easy. PHP has by far the highest “Get in, code, get out” factor that I have found in a language, and until another language comes around that can do better on this scale, I will be using PHP for many more years to come.

Update: Discussion on Hacker News and Google+

Published at DZone with permission of Cedric Beust, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)


Michal Hlavac replied on Thu, 2011/08/11 - 11:33am

No offense, but why do you write post like this to java dzone?

Ryan Developer replied on Thu, 2011/08/11 - 12:01pm

+1 Michal: I read JavaLobby because I want to read about Java, not PHP or Scala or Clojure or Ruby

Jose Maria Arranz replied on Thu, 2011/08/11 - 12:50pm

"I happily mix up presentation and logic all the time"

Be honest Cedric you code PHP from time to time to feel yourself like a boy doing pranks XD



John Waterwood replied on Fri, 2011/08/12 - 3:46am

I happily mix up presentation and logic
Hahaha! At least you admit it ;-) The signature way of working in PHP is to throw away everything you learned reading Code Complete and Clean Code, forget about every practice and pattern you studied at University, and literally code like there's no tomorrow. The guy after us will clean up the mess, right? Right?

Matt Young replied on Fri, 2011/08/12 - 1:31pm

This is the stupidest post on PHP I have ever seen! Particularly the comparison of PHP to C. The similarities in PHP and C are subjective and are far outnumbered by dis-similarities. Now don't get me wrong, php is pretty decent for coding up some Q&D webpages but it is a far cry from the architectural heavy language like C.

your PHP is easy and C is easy so they are twins is silly. How about the ways they are different.

C is a compiled language PHP is not

C gives you direct low level access to system resources like memory and hardware. PHP um no!

C is a language whose changes are governed by an international standards body. PHP is basically governed by one company Zend.

C has many implementations of the compiler by dozens if not hundreds of different vendors. PHP what compiler?

C runs everywhere. I'm not saying it runs on every os. I'm saying *EVERYWHERE*! Software written in C can be compiled and run on watches, servers, toasters, in-dash car stereos etc. PHP only runs in a webserver and last I checked is only fully functional in 1 webserver, apache.

Development library vendors have targetted C for 20 + years and there are thousands of libraries and frameworks from almost as many vendors. For PHP there is Zend, and more recently cake.

C's documentation outstrips PHP by at least a factor of 4. it is dishonest to try and compare them equivilantly. a quick scan of amazon yielded 18,883 Results for C and 4,301 Results for PHP. Yes PHP has alot of documentation but most of it appears to be basic syntax and setup. It's not real architecurally oriented. C on the other hand has multiple publications on each of a hundred or more highly specified fields of C development from algorithms to Z-scoring statistical analysis.

There is very little code sharing in PHP. There are some open source products like wordpress, squirrelmail and webmin written in PHP but they tend to be homespun solutions to problems and are rarely have architectural writeups on how things are done. Other languages like C and java produce reference implementations of concepts and then pass whitepapers on to the community which makes the community more sophisticated as a whole.

which leads to the final bur under my saddle about PHP. There is no drive to add features to the language to mature the developement within the community. PHP is still just a script engine. If that is all you need there are hundreds of better options. Bash, groovy, ruby etc. If you wanna do php, fine. But be honest about it. There are only 2 reasons to use PHP: You are too lazy to learn a better language and your app is simple enough you can still skate by scripting.

Nabeel Manara replied on Fri, 2012/01/27 - 11:54am

I’ve used php for several years. It is very easy and comfortable. There is a lot of applicable free sources in the internet written by php.
But recently I had to implement encryption on some data from dot net. I searched a lot for encryption methods in php. But It was very disappointing. There isn’t perfect implementation for cryptography. I couldn’t solve padding problem at last. I used dot net in this regard.
In case of data encryption php lets me down!!

Carla Brian replied on Sat, 2012/04/28 - 6:00am

I love Php too. I think everyone is using this espicially for website applications. It is open source and easy to use as well. - Naperville Dentists

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.