Specifications

Its also a good idea to distinguish between variables and constants with casea common
scheme is to use all lowercase for variables (for example, $result) and all uppercase for con-
stants (for example, PI).
One bad practice some programmers use is to have two variables with the same name but dif-
ferent capitalization, just because they can, such as $name and $Name for instance. I hope it is
obvious why this is a terrible idea.
It is also best to avoid amusing capitalization schemes such as $WaReZ because no one will be
able to remember how it works.
You should also think about what scheme to use for multiword variable names. For example:
$username
$user_name
$UserName
are all schemes I have seen used. It doesnt matter which you opt for, but you should try to be
consistent about this. You might also want to set a sensible maximum limit of two to three
words in a variable name.
Function names have many of the same considerations, with a couple of extras. Function
names should generally be verb oriented. Consider built-in PHP functions such as
addslashes() or mysql_connect(), which describe what they are going to do to or with the
parameters they are passed. This greatly enhances code readability. Notice that these two func-
tions have a different naming scheme for dealing with multiword function names. PHPs func-
tions are inconsistent in this regard, presumably partly as a result of having been written by a
large group of people.
Also remember that function names are not case sensitive in PHP. You should probably stick to
a particular format anyway, just to avoid confusion.
You might want to consider using the module naming scheme used in many PHP modules,
that is, prefixing the name of functions with the module name. For example, all the MySQL
functions begin with mysql_, and all the IMAP functions begin with imap_. If, for example,
you have a shopping cart module in your code, you could prefix the function in that module
with cart.
In the end, it doesnt really matter what conventions and standards you use when writing code,
as long as some consistent guidelines are applied.
Building Practical PHP and MySQL Projects
P
ART V
464
28 7842 CH22 3/6/01 3:37 PM Page 464