Microsoft Word - Core PHP Programming Using PHP to Build Dynamic Web Sites

(singke) #1

You do not need to let PHP know about a variable before you use it. Some languages like
C require you to declare every variable along with its type. This is because a specific
amount of memory needs to be set aside. But this is generally a problem associated with
compiled languages, not interpreted ones. The first time you use a variable in PHP, the
engine adds it to the list of variables it knows about and makes a best guess at what type
of data the variable holds.


The first place you use a variable establishes the scope—the range within the code in
which the variable may be seen. Every function you define has its own variable space.
That is, there are variables that exist just for that function, and they are invisible to all
other parts of your script. In addition there is a global scope for variables created outside
any function. In some programming languages global variables are visible inside
functions. This is not the case with PHP. When you create a function in PHP, you must

Free download pdf