Tuesday, November 19, 2024
Google search engine
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

Recent Comments