1

なぜこれがエラーを投げているのか分かりません - 誰かが問題を見てくれることを願っていますか?

$client->set('place', 'home');
$client->placeInfo();
$client->screen($client->response());
$client->unset('place');

致命的なエラー:未定義のメソッド Client::unset() への呼び出し...

クライアントクラス

// stores the client data
private $data = array();
// stores the result of the last method
private $response = NULL;

/**
* Sets data into the client data array. This will be later referenced by
* other methods in this object to extract data required.
*
* @param str $key - The data parameter
* @param str $value - The data value
* @return $this - The current (self) object
*/
public function set($key, $value) {
$this->data[$key] = $value;
return $this;
}

/**
* dels data in the client data array.
*
* @param str $key - The data parameter
* @return $this - The current (self) object
*/
public function del($key) {
unset($this->data[$key]);
return $this;
}

/**
* Gets data from the client data array.
*
* @param str $key - The data parameter
* @return str $value - The data value
*/
private function get($key) {
return $this->data[$key];
}

/**
* Returns the result / server response from the last method
*
* @return $this->response
*/
public function response() {
return $this->response;
}


public function placeInfo() {
$this->response = $this->srv()->placeInfo(array('place' => $this->get('place')));
return $this;
}
4

1 に答える 1

6

unset問題の原因は、そのクラスに定義されたメソッドがないことです。unset予約済みのキーワードであるため、どちらも定義できません。名前のままでメソッドを定義することはできません。

public function unset($foo) // Fatal Error

public function _unset($foo) // Works fine

メソッドの名前を別の名前に変更し、呼び出しを変更します...

編集:編集したばかりのコードを見ると、クラス定義のメソッドであるため、$client->unset('place')をに変更する必要があります...$client->del('place')

于 2011-01-07T19:05:34.793 に答える