ptg16476052
Expanding Your Knowledge of PHP 681
24
As you can see, in this case the page won’t have meaning if the function in the library
page is not available, so using require makes sense. On this page, it wouldn’t matter
whether I used require or require_once because there are no other includes. Suppose
that the page included another file—one that prints the current temperatures around the
world. If that page also had a require() call for temperature_converter.php, the same
code would be included twice. An error would cause the page to fail, because each func-
tion name can only be declared once. Using require_once ensures that your library code
is available and that it is not accidentally included in your page multiple times.
However, if you’re including content that will be displayed within your page, include
or require makes more sense. You don’t have to worry about conflicts, and if you’re
including something to be displayed on the page, chances are you want it to appear, even
if you’ve already included the same thing.
Expanding Your Knowledge of PHP
PHP is a full-featured scripting language for creating web applications and even writ-
ing command-line scripts. What you’ve seen in this lesson is just a brief introduction
to the language. There are more statements, lots more built-in functions, and plenty of
other things about the application for which there isn’t space to discuss in this lesson.
Fortunately, an online version of the PHP manual is available that will fill in most of the
blanks for you. You can find it at http://www.php.net/docs.php.
Also, shelves of books about PHP are available to you. Some that you might want to look
into are Sams Teach Yourself PHP, MySQL, and Apache All in One by Julie Meloni, and
PHP and MySQL Web Development by Luke Welling and Laura Thomson.
There’s more to PHP than just the core language, too. Lots of libraries have been written
by users to take care of common programming tasks that you might run into. There’s an
online repository for these libraries called PEAR, which stands for PHP Extension and
Application Repository. You can find it at http://pear.php.net/.
When you’re writing your applications, make sure to check the PHP manual to ensure
there’s not already a built-in function to take care of whatever you’re doing. If there isn’t,
check PEAR.
As I said before, I left out huge swaths of PHP functionality in this lesson for the sake of
space. Here are some areas that you’ll want to look into before developing your own PHP
applications.