English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP reference manual

PHP is_subclass_of() function usage and example

PHP Class/Object function reference manual

is_subclass_of - If this object is a subclass of the class, it returns TRUE

Syntax

is_subclass_of($object, $class_name);

Definition and usage

It checks whether the given object has class_name class as one of its parent objects.

Parameter

NumberParameters and descriptions
1

object (required)

The object to be tested

2

class (required)

Class name.

Return value

 If the class of the object object is a subclass of class class_name, it returns TRUE, otherwise it returns FALSE.

Online example

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

  PHP Class/Object function reference manual