如何动态加载php代码并检查类是否实现接口 [英] How to load php code dynamically and check if classes implement interface
本文介绍了如何动态加载php代码并检查类是否实现接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在PHP中动态加载一个类。此文件和类名已从数据库中删除。该文件必须包含类和方法。我尝试用界面来解决它,但我真的不知道如何以最美丽的方式做到这一点。
I'm loading a class dynamically in PHP. This file and class name are gotten out of the database. This file must contain a class and a method. I tried to solve it with an interface, but I don't really get it how I could do it the most beautiful way.
你的建议是什么?
推荐答案
使用 class_exists()
确定某个类是否已定义, method_exists()
确定某个类是否有方法并且 instanceof
确定一个类是否实现了接口。
Use class_exists()
to determine if a class has been defined, method_exists()
to determine if a class has a method and instanceof
to determine if a class implements an interface.
这篇关于如何动态加载php代码并检查类是否实现接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文