Syntaxe :bool ReflectionClass::implementsInterface (chaîne $interface)
Paramètres :Ceci La fonction prend un paramètre,
$interface,qui contient l`interface spécifiée à vérifier.
Valeur de retour :la fonction retourne vrai en cas de succès ou faux en cas d`erreur.Les programmes suivants illustrent la fonction ReflectionClass::ImplementsInterface() en PHP :
Programme 1 :< ? php
// Définir quelques interfaces
interface
Collèges {}
interface
Départements {}
in terface
Etudiants {}
interface
Entreprises { }
// Initialisation de la classe d`interface
classe
Interfaces
implémente
Collèges,
Départements, étudiants, entreprises {}
// Utilisation de ReflectionClass sur des interfaces
$A
=
new
ReflectionClass (
"Interfaces"
);
// Appel de la fonction ImplementsInterface()
// via l`interface Colleges
$B
=
$A
-> implementsInterface (
`Collèges`
);
// Obtenir vrai ou faux
var_dump (
$B
);
?>
Sortie :bool (true )
< b>Programme 2 :
< ? php
// Définir l`interface de la société SuperClass
interface
Société
public
fonction
GFG();
}
// Définir une autre interface Société1
interface
Société1
public
fonction
GeeksforGeeks();
}
// Définir la sous-classe Departments
class
Services
implémente
Société
public
fonction
GFG() {}
}
// Utilisation de ReflectionClass() sur
/ / Subclass Departments
$reflect
=
new
ReflectionClass (
`Departments`
);
// Appel de la fonction ImplementsInterface()
$A
=
$reflect
-> implementsInterface (
` Company1`
);
// Obtenir vrai ou faux
var_dump (
$A
);
?>
Quitter :bool (false )
Lien :< b> https://www.php.net/manual/en/reflectionclass.implementsinterface.php