Specifications

representing the file we want to open, and a variable called $openmode containing a string rep-
resenting the mode in which we want to open the file. We chose not to provide the optional
third parameter.
Call to Undefined Function
If you attempt to call a function that does not exist, you will get an error message as shown in
Figure 5.3.
Reusing Code and Writing Functions
C
HAPTER 5
5
REUSING CODE
AND
WRITING
FUNCTIONS
131
FIGURE 5.3
This error message is the result of calling a function that does not exist.
The error messages that PHP gives are usually very useful. This one tells us exactly in which
file the error occurred, in which line of the script it occurred, and the name of the function we
attempted to call. This should make it fairly easy to find and correct.
There are two things to check if you see this error message:
1. Is the function name spelled correctly?
2. Does the function exist in the version of PHP you are using?
It is not always easy to remember how a function name is spelled. For instance, some two-
word function names have an underscore between the words and some do not. The function
stripslashes() runs the two words together, whereas the function strip_tags() separates
the words with an underscore. Misspelling the name of a function in a function call results in
an error as shown in Figure 5.3.
Many functions used in this book do not exist in PHP 3.0 because this book assumes that you
are using at least PHP 4.0. In each new version, new functions are defined and if you are using
an older version, the added functionality and performance justify an upgrade. To see when a
particular function was added, you can see the online manual at www.php.net. Attempting to
call a function that is not declared in the version you are running will result in an error such as
the one shown in Figure 5.3.
07 7842 CH05 3/6/01 3:35 PM Page 131