2011-01-07 76 views
1

我不知道爲什麼這是拋出一個錯誤 - 希望有人能看到這個問題?未設置變量會導致致命錯誤?

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

Fatal error: Call to undefined method 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; 
} 
+0

什麼是「客戶端」類? – lonesomeday 2011-01-07 19:01:22

+0

'unset()'聲明做什麼? – Dan 2011-01-07 19:01:37

回答

6

你的問題的原因是,有對類沒有定義的方法unset。而且你也不能定義一個,因爲unsetreserved keyword。你不能用它的名字來定義一個方法。

public function unset($foo) // Fatal Error 

public function _unset($foo) // Works fine 

重命名方法到別的東西,並更改電話...

編輯:看着你剛纔編輯的代碼,你需要改變$client->unset('place')$client->del('place'),因爲那是方法中的類定義...