English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
PHP Class/Object function reference manual
is_subclass_of - If this object is a subclass of the class, it returns TRUE
is_subclass_of($object, $class_name);
It checks whether the given object has class_name class as one of its parent objects.
Number | Parameters and descriptions |
---|---|
1 | object (required) The object to be tested |
2 | class (required) Class name. |
If the class of the object object is a subclass of class class_name, it returns TRUE, otherwise it returns FALSE.
The following is the usage of this function-
<?php //Define a class class wid_fact { var $oink = 'moo'; } //Define a subclass 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"; } ?>Test and see‹/›
It will produce the following result-
Yes, $WFC is a subclass of wid_fact No, $WF is not a subclass of wid_fact