Неустановленная переменная вызывает фатальную ошибку? - PullRequest
1 голос
/ 07 января 2011

Я понятия не имею, почему это вызывает ошибку - надеясь, что кто-то может увидеть проблему?

$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;
}

1 Ответ

6 голосов
/ 07 января 2011

Причина вашей проблемы в том, что в этом классе нет определенного метода unset.И вы также не можете определить его, потому что unset является зарезервированным ключевым словом .Вы не можете определить метод с помощью его имени.

public function unset($foo) // Fatal Error

public function _unset($foo) // Works fine

Переименуйте метод во что-то другое и измените вызов ...

Редактировать: Глядя на код, который вы только что отредактировали, вам нужно изменить $client->unset('place') на $client->del('place'), так как это метод в определении класса ...

...