Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: Path of interface

I need to know the path of a file in which an interface is defined. I know the name and the interface is available (the file was included at another location in the code). I know things like __FILE__, etc. but the point is, it's only an interface, i do not have an instance. Ironically, i need the path to find a suitable implementation for the interface.

Does anyone know a way to find the path?

Thanks for your help!

like image 647
Ben Avatar asked Jul 17 '26 12:07

Ben


1 Answers

Despite the name, ReflectionClass works on interfaces too. So you can use

$interface = new ReflectionClass('IFoo');
echo $interface->getFilename();
like image 71
Gordon Avatar answered Jul 19 '26 01:07

Gordon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!