PHP:接口路径

发布于 2024-09-27 07:52:17 字数 155 浏览 0 评论 0原文

我需要知道定义接口的文件的路径。我知道名称和接口可用(该文件包含在代码中的另一个位置)。我知道诸如 __FILE__ 等之类的东西,但重点是,它只是一个接口,我没有实例。具有讽刺意味的是,我需要找到合适的接口实现的路径。

有谁知道找到路径的方法吗?

感谢您的帮助!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云醉月微眠 2024-10-04 07:52:17

尽管有这个名字,ReflectionClass 也适用于接口。所以你可以使用

$interface = new ReflectionClass('IFoo');
echo $interface->getFilename();

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

$interface = new ReflectionClass('IFoo');
echo $interface->getFilename();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文