Just nu får jag http error-koden 401 från API:n jag arbetar mot och det har med att göra att API-nyckeln inte följer med i Client som jag extendar i Person. Så hur gör jag så all data följer med vid en extend?
Kod:
$client = new Client("53fsdt56gdfg");
$person = (new Person(1))->overview();
Client class
Kod:
class Client {
protected $_api_key;
public function Client($_api_key) {
$this->_api_key = $_api_key;
}
protected function sendRequest($method)
{
// do request
// return json
}
}
Person class
Kod:
class Person extends Client {
private $id;
public function Person($id) {
$this->id = (int) $id;
}
public function overview() {
return $this->sendRequest("overview/{$this->id}");
}
}