Saturday, March 26, 2011

Tips for PHP beginners.

Its just recent that I started to code in PHP. I had a good experience in learning it and believe me,if you like coding,you surely gonna love PHP  too. And following are the some of the things that I felt one should take care of, while writing PHP codes..

1.Decide the structure of  your website before writing any code.
 What I mean is you should pre plan the structure of all directories ie what all directories you are gonna use and what sub-directories you will be using in each of them.

2.Name relevantly.
 Each of file should have a name which shows what purpose it serves and so that you can know what a file does by looking at its name itself (and avoid opening it just to see what it does.)

3.Never move your files from one directory to other.
 As I have said earlier that you should decide the structure of your directories before hand itself, and if you don't and at a later stage create a new directory and move files into it,you might face serious problem. For example if you have included these moved files in some other files(using the "include" option), you will have to find every such file and change the path of the moved file. And that is really cumbersome.

4.Never rename your files.
The problem with renaming is same as that of earlier one and if  you still rename it, you will have to change the name of this file everywhere you have included it.

5.PHP debugging.
 Debugging is the most important part of any language. And hence you ought to be very  careful while coding. You can debug segment wise in PHP. ie if you find many errors and cant go about finding it, just comment out  everything except the first segment(ie an if/for/while/some part of code within braces) and execute it. If it works fine, try next segment and so on. Another method to debug is to use the var_dump() function. It basically gives all the contents regarding its type,value etc about the variable included within the parentheses.
Example: If you get T_VARIABLE error,it means you haven't closed the previous statement with a ;(semicolon).

Please consider commenting if you like this post/ you have other suggestions.

No comments:

Post a Comment