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 回答