这个问题在这里已经有了答案:
Can I extend a class using more than 1 class in PHP?
(20 个回答)
1年前关闭。
我听说你不能使用两次extend。
我有两个类:
Base32 和 SecureRandom
我需要 TOTP。
我怎样才能使用这两者呢?
最佳答案
使用interfaces或 composition (包括一个类的实例作为类的成员变量)。
接口(interface)允许您为类中的方法定义原型(prototype)。接类implements
该接口(interface)并且必须为接口(interface)中的每个原型(prototype)定义一个方法。您只能直接从一个类 ( extends
) 继承,但您可以 implements
任意数量的接口(interface)。
如果您发现界面不适合您的任务,请使用组合。
关于php - PHP 中的多个扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5768518/