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. You should not
use any other superglobal arrays in this class (they are not necessarily bad, but
you are likely misusing them if you include them in HW assignments, and they are
outside the scope of this course).
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($new_x) { foo(); $x = $new_x; $y++; }