It's been a few years since I echo'd my first HELLO WORLD script. PHP has developed and evolved and yes, it has changed since it was first devised as little Perl extensions on Rasmus Lerdorf's localhost. Still, for a little Home Page script, it has grown into something that is now used on over 200 million websites around the world. That is nothing to be scoffed at. In this article we'll discuss the two most important things we should try to remember when developing in PHP.
While we all know that PHP is not perfect, I seriously doubt that anything can be done about that right away. That said, there are not many languages that can run pretty much the same in version 6 as they could in version 3 (Yes, I did read what I just said, and I have an old php3 script that still runs on PHP 5, and should run on PHP 6, ok? Ok.) Development in PHP is always a tricky road to follow considering that you are developing something that will not usually run on a server that you have real control over--unless you are lucky enough to be able to afford your own server--and be viewed on a multitude of browsers that all display elements differently, anywhere in the world, over a connection that is usually shakey at best.
Knowing all of this, what are the two most important things we should we try to remember when developing in PHP?
1. Develop On Linux.
This is not really a RULE, but it is pretty cool to know that the server on your laptop or home pc is actually set up exactly like the server you are going to run your application on. The reasons? Quite simply, you will be developing on a local server (localhost) that is usually Windows-based, right? And when you deploy your application / website, it is going to run on a Linux server? The semantics might not mean anything to you, but what is important is that Windows-based servers are not really case sensitive. In other words, you could have a url like http://mysite.com/folderName/ when you set up your website on your Windows localhost. Mostly you might think this looks cool. So you set up all of your links like that, and everything is just perfect. Then off you go and upload your site to your webserver and...well, the link does not work, even though you have tested everything a million times. I promise you--because I have done it--that you will not think about the capitalization the first time it happens to you. Trust me. All you get is a "page not found" error even though you know the page exists. Frustrating and time killing if you have more than ten links on your website.
Besides that, Linux is a very stable environment to develop on. Our company development server is an Ubuntu-based OS that runs 24 hours a day, 7 days a week, and has never, ever been shut down or turned off in the last four years. In that same time it has never crashed or frozen. To me that is respectable.
If you are really unable to tear yourself away from Windows, you need to try to get your development environment setup to mimick Linux as best you can. That way you will have less surprises when you upload your application to its production server.
2. Use SVN or CVS
SVN and CVS are essentially two sides of the same coin. If you have not heard of them (I use SVN, or subversion) what they basically do is save your work in a system that makes it possible to restore previous versions should the need arise. And trust me--the need arises. Most developers will argue that SVN is only really necessary when you have multiple developers working on the same project. What this means is that multiple developers can work on the same file at the same time, and SVN will simply handle the conflicts by merging all of the work into one file wherever possible. It's my opinion, however, that even if you are working alone, SVN is very important. I have SVN on my localhost, and we use it at the office too--yes, it's running on the DIE HARD Ubuntu Server. What is nice about this is that we can always go back to a previous version of a project and restore it to that point, making it really convenient should you need to branch off in a diferent direction.
As you can see, what I have spoken about here is actually relevant to development as a whole, rather than just PHP. However, knowing what I do about how PHP development tends to spiral and mushroom into an enormous multi-headed monster, should we not plan or concentrate--or both? These are the very first two things I can suggest that you do in order to get started in development of applications that are not only developed in a controlled and structured environment, but in an environment that mimmicks the production environment as much as possible. It's the most effective way to start as it gets.