This will
make your code much more stable.
include_once("../ch2/class.emailer.php");
if( class_exists("Emailer"))
{
$emailer = new Emailer("hasin@pageflakes.com");
}
else
{
die("A necessary class is not found");
}
?>
Finding Currently Loaded Classes
In some cases you may need to investigate which classes are loaded in the current
scope. You can do it pretty fine with the get_declared_classes() function. This
function will return an array with currently available classes.
include_once("../ch2/class.emailer.php");
print_r(get_declared_classes());
?>
You will see a list of currently available classes on the screen.
Finding out if Methods and Properties Exists
To find out if a property and/or a method is available inside the class, you can
use the method_exists() and property_exists() functions. Please note, these
functions will return true only if the properties and methods are defined in
public scope.
Checking the Type of Class
There is a function called is_a() that you can use to check the type of class. Take a
look at the following example:
class ParentClass
{
Chapter 3
[ 47 ]
}
class ChildClass extends ParentClass
{ }
$cc = new ChildClass();
if (is_a($cc,"ChildClass")) echo "It's a ChildClass Type Object";
echo "\n";
if (is_a($cc,"ParentClass")) echo "It's also a ParentClass Type
Object";
?>
You will find the output as follows:
Its a ChildClass Type Object
Its also a ParentClass Type Object
Finding Out the Class Name
In the previous example we checked the class if it's a type of a known one.
Pages:
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69