Answer the question
In order to leave comments, you need to log in
How to check if an interface exists in PHP without creating an instance?
The class name comes to the method, it is necessary to check this class for the implementation of the interface with minimal effort. Right now I'm doing (new $class) instanceof $interface . But it seems to me a bit unreasonable to create an instance of a class just to test the interface. Moreover, I do not want to create a Reflection object because it looks even worse. Any ideas how to make it less time consuming for the system?
Answer the question
In order to leave comments, you need to log in
interface MyInterface { }
class MyClass implements MyInterface { }
$interfaces = class_implements('MyClass');
if($interfaces && in_array('MyInterface', $interfaces)) {
// Class MyClass implements interface MyInterface
}
Thanks adamsafr for the answer :
Fits?
stackoverflow.com/questions/20169805/php-check-if-...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question