Home Designing and Linking PHP Files

Using Superglobals

The superglobal arrays like $_GET and $_POST should be considered read-only. You should not store new values in them or modify existing values in them as a way of avoiding using regular local variables. (The $_SESSION superglobal array is an exception to this rule, if the assignment involves managing user login sessions. It is meant to be written into directly by your code.)

Function Placement

Place all of your functions at the very top or bottom of your PHP file, never in the middle of the page.

HTML Validation

All HTML content output from a PHP file should pass the HTML validator. Choose the "View Source" option in your browser to get the HTML ouptut, then copy/paste this into the validator.

Minimize Code Redundancy

If you repeat the same code two or more times, find a way to remove the redundant code so that it appears only once. For example, place it into a helper function that is called from both places. If the repeated code is nearly but not entirely the same, try making your helper function accept a parameter to represent the differing part.

foo();
$x = 10;
$y++;
...

foo();
$x = 15;
$y++;
helper(10);
helper(15);
...

function helper($newX) {
  foo();
  $x = $newX;
  $y++;
}