gpt4 book ai didi

php - PHP 中的多个扩展

转载 作者:行者123 更新时间:2023-12-02 07:47:44 27 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





Can I extend a class using more than 1 class in PHP?

(20 个回答)


1年前关闭。




我听说你不能使用两次extend。

我有两个类:

Base32 和 SecureRandom

我需要 TOTP。

我怎样才能使用这两者呢?

最佳答案

使用interfacescomposition (包括一个类的实例作为类的成员变量)。

接口(interface)允许您为类中的方法定义原型(prototype)。接类implements该接口(interface)并且必须为接口(interface)中的每个原型(prototype)定义一个方法。您只能直接从一个类 ( extends ) 继承,但您可以 implements任意数量的接口(interface)。

如果您发现界面不适合您的任务,请使用组合。

关于php - PHP 中的多个扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5768518/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com