I like PHP
Join the DZone community and get the full member experience.Join For Free
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.
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”).
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.
Published at DZone with permission of Cedric Beust, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.