Wednesday, June 17, 2026
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
32516 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6897 POSTS0 COMMENTS
Nicole Veronica
12014 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6964 POSTS0 COMMENTS