Why Use PHP For Your Website?

With a degree in computer information systems from Mohawk Valley Community College, John worked for small businesses and performed freelance work before joining Site-Seeker in 2007.

I am often asked why and sometimes criticized for my choice of PHP as my main Web development language and the fact that I do not spend time trying to learn, nor do I have much interest in learning other languages better. There are reasons why I have made these choices and I thought I would share them.

Built for the Web

Of all the possible programming and/or scripting languages there are for developing Web applications, there are only two that came about as a direct result of the Web and that were built specifically with the Web in mind. These two are PHP and ColdFusion. Everything else, as far as I am aware, had their roots outside the Web and have had functionality for the Web added later (sometimes with the use of a sledge hammer.) Since I am a developer whose main focus is on building applications for the Web I have to ask myself why wouldn’t I choose a platform to develop on that was designed specifically for what I’m doing. PHP does an excellent job at what it was designed for and, as of yet, they have not saw fit to try to hammer in functionality to make it anything more. PHP’s focus is the same as mine, the Web, and it does not dilute that focus by adding in the ability to develop applications that are not Web based.

Array Handling

Arrays are probably by far the main reason that I love PHP, but then again I love arrays. Many other languages make arrays and handling arrays a chore to be avoided. There are two main things that make arrays in PHP much easier to use.

  1. PHP is Untyped: What does that mean? It means that I can use a variable to hold any type of information that I want. I can put a string into a variable and later, if I choose, I can change the variable’s contents to a number. When it comes to arrays this means that one array can hold mixed information with some values being numbers and some values being strings and yet other values being any type of value that the language can use. Most other languages do not allow this freedom and require all data in an array to be of the same type. If you need to have an array that holds mixed types of data you must instead use multiple arrays, one for each type of data, or you need to store everything as a string and then convert it to the type of data you need each time you want to use it for something, if the language allows this conversion.
  2. Strings as Subscripts: In many programming languages array subscripts can only be numbers: 0, 1, 2, etc. So if I have an array of data I must remember what data I stored in what subscript. This may be good for simple, one dimensional arrays but if you start getting more complex then you need to keep a map to keep track of what’s going on and what data is stored where. On the other hand, PHP allows me to use strings as subscripts, so if I have data about a person I can use subscripts like: “first_name”, “last_name”, “address”. I no longer need to remember that I put a persons address in array X subscript 3, I can just use $X[‘address’]. If the data in an array that uses numbers as subscripts changes you may be talking about a large change in the way the application is built. With stings as subscripts there is very little that needs changing since I know that “first_name” will always hold the data I expect.

Arrays are one of those things in programming that make life as a programmer easier. I’ve spoken with developers that use other languages and most of the time they don’t particularly care for using them and find other more complicated ways of doing the job that needs to be done; they avoid them, some even hate them. I believe the main reason for this is that other languages have made them too complicated to use well.

Same syntax as JavaScript

No matter what language you use on the server, JavaScript is the language used by 90% of Web developers for client side programming. PHP and JavaScript are both based on C++ and because of this they have very similar syntax. It is extremely easy to switch between the two making life less complex.

Free

You simply cannot beat the price.

  • *Nix operating system: Free
  • Apache Server: Free
  • PHP: Free
  • MySQL: Free
  • JavaScript: Free
  • Addons Required: None

Why focus on a single language?

The truth is that I do not focus on just a single language and I am not just a programmer. I’ve worked at places where everyone works in their own silo. The designer designs and (s)he has very little knowledge about HTML and CSS; The HTML/CSS guys/gals no very little about design and even less about programming; The programmers understand only the basics about HTML and CSS and may not know much about how to design a database and leave this up to the DB gurus.

My personal opinion is that this is a bad model for Web Development. I feel that in order to do the best job I can do is to understand all aspects of it. And not just to understand them, but to understand them well and to understand how they work together or how you can make them work together; to grasp the bigger picture. This means that I need to be an expert in more than just server languages. It means that I need to be an expert in HTML, CSS, JavaScript, XML, JSON, SQL and a host of others. It means that I also need to understand design. It means that I also need to understand how to design a good database. Not to mention keeping up with all the browsers that are available and how they will display my work.

While many of the things I’ve mentioned above are not programming languages, they are things that take considerable effort to understand and keep up with and I consider myself to be an expert in many of them and they do take a considerable amount of my time to keep up with. This time far exceeds the time that I spend at work actually performing my job. But then again, this is not just a job for me.

Programming is programming… Right?

I’ve heard this said by professors, and I’ve heard this said by non-programmers, but I’ve not heard many programmers say the same thing. “Programming is programming, only the syntax changes.” I personally think of this as a myth.

It is true, programming is programming. The logic involved is the same. However, as Yogi Berra said, “In theory, there is no difference between theory and practice. But in practice, there is.” Yes, that was a quote by a baseball player; however, it is just as applicable to programming as it is to baseball.

While the logic involved is the same, often times the syntax is so dissimilar that there is no way to equate one language with another. The steps involved in getting the same result to the same problem are often completely different. What makes sense in theory may not be practical, especially in the world of Web development. When building an application for the Web it not only needs to work and work well, it also needs to allow for rapid and easy changes in the future. This rapid, easy change comes from knowing everything there is to know about a single language and the only way to really know a language is to focus on it, to love it, to be devoted to it.

A note about frameworks

As a Web developer I also do not pay much attention to frameworks. The reasons for this are the same as my reasons for not being interested in learning other languages, because learning a framework is like leaning another language. Usually, while based on a specific language, these frameworks end up being so different that there are few similarities in the end result. Not to mention the fact that frameworks come and go like fads requiring you to relearn a new language every time the fad changes. Things like PHP and JavaScript are not fads and they are not likely to go anywhere or change significantly. For me it is simply smarter to understand them in all their intricacies, removing the need to rely on someone else to create a framework so I can do my job. Frameworks also require me to conform to someone else’s idea of what the best practice in a given situation is and I am nothing if not a non-conformist. One could say that I go out or my way to not conform, to not fit into the mold others think I should fit into. Of course, I don’t go out of my way to not conform, but then I don’t go out of my way to conform either.