我听说你不能使用两次extend。
我有两节课:
Base32 和 SecureRandom
我需要 TOTP。
我怎样才能使用这两者呢?
看看PHP5.4 Traits,它们可以解决多重扩展的问题。
将它们与接口结合以获得实例功能。
例如:
interface ClientAwareInterface {
public function setClient($client);
}
trait ClientAwareTrait {
protected $client;
public function setClient($client)
{
$this->client = $client;
}
}
class Shop implements ClientAwareInterface extends SomeClass {
use ClientAwareTrait; // use our trait to implement interface methods
use OtherTrait;
}
$shop = new Shop();
if($shop instanceof ClientAwareInterface) {
$shop->setClient('test');
var_dump($shop);
}
结果将是:
object(Shop)[1]
protected 'client' => string 'test' (length=4)
PHP 不允许多重继承。您需要扩展其中一个并将另一个作为私有变量或类似的东西。