どちらが正しいのか知りたいですか?
// the origional JAVA method
public void setRequestHeader(String key, String value) {
if (this.headers == null) {
this.headers = new HashMap<String, String>();
}
this.headers.put(key, value);
}
これはPHPで次のように解釈されますか
Class HashMap {}
/**
* @return this
*/
public function setRequestHeader($key, $value) {
if ($this->headers == NULL) {
$this->headers = new HashMap();
}
return $this->headers->$key = $value;
}
....また....
/**
* @return array
*/
public function setRequestHeader($key, $value) {
if ($this->headers == NULL) {
$this->headers = array();
}
return $this->headers[$key] = $value;
}
私が信じているように連想配列が正しい場合、クラスの最上位でこの変数を宣言する必要がありますか?
// JAVA version
private HashMap<String, String> headers;
に似ているだろう
// PHP version
private $headers = array();