PHP | ReflectionClass implementsInterface() Function
Last Updated :
11 Dec, 2019
The ReflectionClass::implementsInterface() function is an inbuilt function in PHP which is used to check the specified interface is present or not.
Syntax:
bool ReflectionClass::implementsInterface( string $interface )
Parameters: This function accepts a single parameter $interface which holds the specified interface which are being checked.
Return Value: This function returns true on success or false on failure.
Below programs illustrate the ReflectionClass::implementsInterface() function in PHP:
Program 1:
<?php
interface Colleges { }
interface Departments { }
interface Students { }
interface Companies { }
class Interfaces implements Colleges,
Departments, Students, Companies { }
$A = new ReflectionClass( "Interfaces" );
$B = $A ->implementsInterface( 'Colleges' );
var_dump( $B );
?>
|
Program 2:
<?php
interface Company {
public function GFG();
}
interface Company1 {
public function GeeksforGeeks();
}
class Departments implements Company {
public function GFG() {}
}
$reflect = new ReflectionClass( 'Departments' );
$A = $reflect ->implementsInterface( 'Company1' );
var_dump( $A );
?>
|
Reference: https://www.php.net/manual/en/reflectionclass.implementsinterface.php
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...