Preface to PHP

By: Mojtaba | Posted: 2009-04-27 14:21:20 | Wordcount: 1345

Welcome, reader, to the world of PHP.

You're about to learn to use the most powerful web development language that can be found, and, what's more, you will do so with the minimum of fuss.

I myself started programming in PHP back in 2001 when Perl was at its apogee, and after only two weeks, I had converted most if not all of my scripts into PHP. The reasons I were drawn so strongly towards PHP are many, but mainly it was ease of use – even after having used Perl and ASP so.

Through this blog, I hope for you to be able to switch to PHP in the same kind of time frame, if not less. Back when I made the switch, I was not lucky enough to have a resource like this to learn from!

I am writing this blog with the goal of making the task of learning PHP something fun that you do not have to worry about. As such, you will find lots of information for newcomers, even those who have not programmed much before. On the other end of the scale, I must admit that I have worked hard to put in this blog lots of information on advanced functionality in PHP – if you are a veteran user looking to take your PHP skills above and beyond where they are right now, I am hoping you will find there is lots to be had here.

My goal for this blog is to produce a tutorial you can read in whatever order you want. Once you have the basics down, I encourage you to flick through the table of contents, find something that interests you most, and start reading from there.

This tutorial will be write as a blog, which means you can either use the "Next" and "Back" links at the end of every page to browse your way through the tutorial, or you can just click the links that interest you most.

 

Who this Tutorial is not for

If you don't fit into one of these categories, you are doing well already:

  1. People who want more pictures than words
  2. People who do not trust open-source software
  3. People who aren't willing to commit a little time each day or every few days to try out code examples for themselves

I cite the last category particular because of Flip Wilson's law: "You cannot expect to hit the jackpot if you do not put a few nickels in the machine".

 

A note for programmers coming from Perl to PHP

Before using PHP, Perl was my language of choice for web applications, so I am not short of experience in the language.

The common denominator between PHP and Perl is that they both have roughly the same roots: they are both Unix-like languages, loosely based on C. As such, one of the biggest advantages and the biggest disadvantages in having already learnt Perl is look-alikes. That is, functions or constants that look almost the same, but are different. Or, worse yet, functions that are called the same name but function differently.

For example, the PHP function substr() looks just like the Perl function substr(). Happily enough, it works in precisely the same manner in both languages. On the other hand, a function like rtrim() looks to many like the Perl function chomp() because it trims whitespace from the right-hand side of a string. However, it is actually quite different in that the Perl version only trims new-line characters and returns the number of characters that have been trimmed, whereas the PHP version trims all whitespace by default, and returns the trimmed string.

I strongly recommend that you consult a reference (either this tutorial or the PHP online manual) if you ever have any doubts as to how a function works. Don't just assume that because a function has the same name that it works in the same way!

 

A note for programmers coming from C or Java to PHP

The syntax and thinking behind PHP is directly based upon C and C++, and it shares many similarities with these languages – particularly when it comes to file handling and operating system functions. Having said that, PHP dispenses with much of the complexity seen in these languages – like Java, PHP only uses references, with no concept of pointers. Similarly, PHP will also perform automatic garbage collection for you, as with Java, although the PHP garbage collection is somewhat less aggressive.

To give you an idea of what you are getting yourself into, please read this short checklist below:

  • PHP has object orientation, including access modifiers, inheritance, abstract and final classes, and more.
  • PHP does not have multiple inheritance. Instead, it follows Java's plan of allowing classes to implement an arbitrary number of interfaces.
  • PHP has flexible error handling using try/catch
  • PHP does not have operator overloading or function overloading
  • PHP has a flexible extension system based on C, so if you are familiar with C you can go ahead and make your own extensions.

 

Tips for success

Despite my best efforts to cut out as much fluff as possible, this will be still quite a long tutorial, and programming is largely a dry topic. Having said that, learning PHP need not be a case of reading a chapter a day and memorising things as you go, and there are a number of tips I want to share with you before you start reading that will help you get the most out of this tutorial:

  • Don't try to memorise things in mass. I will make it quite clear if there is something that is very important for you to remember, but to be frank that will be rare – trying to remember hundreds of functions or parameters or bits of jargon will only slow your learning if anything.
  • Don't rush yourself. Yes, it is fun to learn, and you are going to have a great time learning PHP I can promise you, but that does not mean you should try to hit the ground running. Take it easy, and you will remember things better, enjoy the tutorial more, and become a better programmer as a result.
  • Familiarise yourself with the language. Once you know a few bits and pieces, get started using them straight away. There is a surprising amount of functionality you can put together knowing just a few simple commands, and that's before you try hooking them all together into bigger and better things. So, get started using PHP as early as you feel comfortable.
  • Be creative. If you want to try out something crazy, go for it – the only way you are going to learn is by trying, and, yes, failing too.
  • Program in an environment that suits you. This might be your bedroom, in the dark, in the early hours of the morning, or it might be on a laptop in a park somewhere. The great thing about programming is that there are no restraints on how you do it – think of it like freestyle art.
  • Don't over-do it. If you are a caffeine hog like most geeks, sure, go ahead and drink coffee all you want - I get my fix from Mountain Dew, which has kept me going on many all-nighters. Having said that, you are not helping yourself if you fall asleep reading this tutorial night after night, and neither is it a good thing to program when you are half awake – there is nothing worse than waking up at a desk the next morning and not having the foggiest clue how the code you wrote last night works.
  • Finally, remember that programming is supposed to be fun. If you find yourself hitting a mental brick wall repeatedly, you are doing something wrong. This tutorial is structured so that you keep getting newer and harder challenges to push your programming talents further, but feel free to stop at any point and take a walk in the park.

Enjoy the tutorial!


About the Author:

Printed From: http://www.cyberical.com/blog/preface-to-php.html
Back to the original article