13.09.2016 Views

PHP and MySQL Web Development 4th Ed-tqw-_darksiderg

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Using Functions in <strong>PHP</strong><br />

145<br />

Calling an Undefined Function<br />

If you attempt to call a function that does not exist, you will get an error message, as<br />

shown in Figure 5.3.<br />

Figure 5.3<br />

This error message is the result of calling a function that<br />

does not exist.<br />

The error messages that <strong>PHP</strong> gives are usually very useful.The one in the figure tells<br />

you exactly in which file the error occurred, in which line of the script it occurred, <strong>and</strong><br />

the name of the function you attempted to call.This information should make it fairly<br />

easy to find <strong>and</strong> correct the problem.<br />

Check these two things if you see this error message:<br />

n Is the function name spelled correctly?<br />

n Does the function exist in the version of <strong>PHP</strong> you are using?<br />

You might not always remember how a function name is spelled. For instance, some<br />

two-word function names have an underscore between the words, <strong>and</strong> some do not.<br />

The function stripslashes() runs the two words together, whereas the function<br />

strip_tags() separates the words with an underscore. Misspelling the name of a<br />

function in a function call results in an error, as shown in Figure 5.3.<br />

Some functions used in this book do not exist in <strong>PHP</strong>4 because this book assumes<br />

that you are using <strong>PHP</strong>5. In each new version, new functions are defined, <strong>and</strong> if you are<br />

using an older version, the added functionality <strong>and</strong> performance justify an upgrade.To<br />

see when a particular function was added, you can check the online manual. Attempting<br />

to call a function that is not declared in the version you are running results in an error<br />

such as the one shown in Figure 5.3.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!