The is_subclass_of() function checks if the object has this class as one of its parents.
Syntax
is_subclass_of(object, class, string)
Parameters
object − The tested object
class − The name of class
string − If set to false, the string class name as object is not allowed.
Return
The is_subclass_of() function returns TRUE if the object “object” belongs to a class which is a subclass of “class”, FALSE otherwise.
The following is an example −
Example
<?php
// define a class
class wid_fact {
var $oink = 'moo';
}
// define a child class
class wid_fact_child extends wid_fact {
var $oink = 'oink';
}
// create a new object
$WF = new wid_fact();
$WFC = new wid_fact_child();
if (is_subclass_of($WFC, 'wid_fact')) {
echo "yes, \$WFC is a subclass of wid_fact \n";
} else {
echo "no, \$WFC is not a subclass of wid_fact \n";
}
if (is_subclass_of($WF, 'wid_fact')) {
echo "yes, \$WF is a subclass of wid_fact \n";
} else {
echo "no, \$WF is not a subclass of wid_fact \n";
}
?>The following is the output −
Output
yes, $WFC is a subclass of wid_fact no, $WF is not a subclass of wid_fact