Prev | Current Page 56 | Next

Hasin Hayder

"Object-Oriented Programming with PHP5"


This chapter will also introduce us to the Iterators for easier array access. To store
any object for later use, we need to use a special feature in OOP which is called
serialization, we will also learn about this here. As a whole this chapter will
strengthen your base in OOP.
Class Information Functions
If you want to investigate and gather more information regarding any class, these
functions will be your light in the dark. These functions can retrieve almost any
information regarding a class. But there is an improved version of these functions
and is introduced as a totally new set of API in PHP5. That API is called reflection.
We will learn about reflection API in Chapter 5.
Checking if a Class Already Exists
When you need to check if any class already exists in the current scope, you can use
a function named class_exists(). Have a look at the following example:
include_once("../ch2/class.emailer.php");
echo class_exists("Emailer");
//returns true otherwise false if doesn't exist
?>
More OOP
[ 46 ]
The best way to use the class_exists() function is to first check if a class is already
available. You can then create an instance of that class if it is available.


Pages:
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68