Friday, November 21, 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
32405 POSTS0 COMMENTS
Milvus
97 POSTS0 COMMENTS
Nango Kala
6781 POSTS0 COMMENTS
Nicole Veronica
11928 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11995 POSTS0 COMMENTS
Shaida Kate Naidoo
6907 POSTS0 COMMENTS
Ted Musemwa
7166 POSTS0 COMMENTS
Thapelo Manthata
6862 POSTS0 COMMENTS
Umr Jansen
6847 POSTS0 COMMENTS