我开始为预定义的 php 包编写一个包装类。以下是课程:
class phpclass1
:: ping()
:: __construct(array $options)
:: clear()
:: addDoc(phpclass2 $string)
...
class phpclass2
:: __construct()
:: update()
...
以下是我为上述 2 个类编写的包装类:
class wrapper1 {
private $conn;
public function __construct(phpclass1 $object) {
$this->conn = $object;
}
public function add(wrapper2 $document) {
return $this->conn->addDoc($document);
}
}
class wrapper2 extends phpclass2 {
private $doc;
public function __construct() {
$this->doc = new phpclass2();
}
}
Here's how I'm using them:
$options = array (...);
$object = new phpclass1($options);
$conn = new wrapper1($object);
$doc = new wrapper2();
....
....
$conn->add($doc);
在我使用该功能之前,一切add
正常。它给出了一个错误:Argument 1 passed to phpclass1::addDoc() must be an instance of phpclass2, instance of wrapper2 given
我错过了什么?我尝试了很多东西,但在这里完全迷失了。