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

(singke) #1

Freeing Memory


Each time you create a variable, system memory is set aside for it. Although there is a
limit to the memory available to any computer, you will rarely need to consider
conserving its use when programming in PHP. Your scripts are likely to use very small
amounts of data. And when your script finishes, the memory needed for variables is freed
for use by other processes.


I am simplifying the process somewhat. There are some ways in PHP to create memory
that persists longer than a single page load, and in modern operating systems physical
memory does not match one-for-one with a program's view of available memory. In most
cases you will be doing fine to consider that memory is a finite but abundant resource.


If you do run into memory shortages, or have some other reason for destroying a variable,
you use the unset statement. This statement completely removes a variable or an array
element from memory. The variable name itself will no longer be recognized. Paired with
this statement is the isset function discussed in Chapter 9. This function returns TRUE
when a variable exists.


Constants


Constants are similar to variables, but they may be set only once. Some of them are
created automatically by PHP; others you will create with the define function discussed
in Chapter 9. You do not use the dollar-sign operator to get the value of a constant, and a

Free download pdf