Friday, October 10, 2025
HomeLanguagesPHP | ReflectionClass isSubclassOf() Function

PHP | ReflectionClass isSubclassOf() Function

The ReflectionClass::isSubclassOf() function is an inbuilt function in PHP which is used to check if any subclass is available or not.

Syntax:

bool ReflectionClass::isSubclassOf( $class )

Parameters: This function accepts a single parameter class which is the class name being checked against.

Return Value: This function returns TRUE if the subclass is available, otherwise FALSE.

Below programs illustrate the ReflectionClass::isSubclassOf() function in PHP:
Program 1:




<?php
  
// Initialising a user-defined superclass Company
class Company {
    public function neveropen() {}
}
  
// Creating a subclass Departments 
class Departments extends Company {
    public function HR_Department() {}
}
  
// Using ReflectionClass() 
$subclass = new ReflectionClass('Departments');
  
// Calling the isSubclassOf() function
$Result = $subclass->isSubclassOf('Company');
  
// Getting the value true or false
var_dump($Result);
?>


Output:

bool(true)

Program 2:




<?php
  
// Initialising a user-defined class Departments
class Departments {
    public function CSE() {}
}
  
// Using ReflectionClass() over the
// user-defined class Departments
$subclass = new ReflectionClass('Departments');
  
// Calling the isSubclassOf() function
$Result = $subclass->isSubclassOf('Departments');
  
// Getting the value true or false
var_dump($Result);
?>


Output:

bool(false)

Reference: https://www.php.net/manual/en/reflectionclass.issubclassof.php

RELATED ARTICLES

Most Popular

Dominic
32350 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6718 POSTS0 COMMENTS
Nicole Veronica
11880 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11941 POSTS0 COMMENTS
Shaida Kate Naidoo
6838 POSTS0 COMMENTS
Ted Musemwa
7101 POSTS0 COMMENTS
Thapelo Manthata
6794 POSTS0 COMMENTS
Umr Jansen
6794 POSTS0 COMMENTS