我試圖用這個方法:如何僅在PHP方法參數中聲明字符串?
public function setMessage(string $message){
$this->message = $message;
}
然後我得到這個錯誤:
Catchable fatal error: Argument 1 passed to notifier::setMessage() must be an instance of string, string given
顯然PHP是解釋string
作爲類名。有沒有看起來像做出這種聲明的解決方案?
唯一例外的是'array'。 – Leri
謝謝 - 更新。 – MrCode
換句話說:只對非標量類型進行打字處理。 – lafor